在supported codecs页面上,AMR-NB被列为在各种平台上都支持编码和解码的少数编码之一。但是,明显没有任何AudioEncodingProperties
“创建”方法,例如AudioEncodingProperties.CreateMp3
,但没有相应的AudioEncodingProperties.CreateAmr
方法。手工创建AMR编码器的所有尝试均因基于经典模棱两可的基于UWP HRESULT的异常而失败。
例如,
var capture = new MediaCapture();
await capture.InitializeAsync(new MediaCaptureInitializationSettings
{
MediaCategory = MediaCategory.Speech,
StreamingCaptureMode = StreamingCaptureMode.Audio
});
var recordProfile = new MediaEncodingProfile
{
Audio = new AudioEncodingProperties
{
BitsPerSample = 16,
ChannelCount = 1,
SampleRate = 8000,
Subtype = "AMRNB"
}
};
ContainerEncodingProperties containerProperties = new ContainerEncodingProperties
{
Subtype = "AMR" // tried this with every known container
};
recordProfile.Container = containerProperties;
recordProfile.Video = null;
var file = await KnownFolders.VideosLibrary.CreateFileAsync("captured.amr",
CreationCollisionOption.ReplaceExisting);
await capture.StartRecordToStorageFileAsync(recordProfile, file); // this throws
结果为System.Exception: 'The requested attribute was not found. (Exception from HRESULT: 0xC00D36E6)'
最佳答案
必须添加此行以设置“自动预设模式”:
recordProfile.Audio.Properties.Add(new Guid("23e5cad8-a3fc-4f0f-97c3-dff51d03bc92"), 1.ToString());
关于c# - 使用UWP以AMR-NB编码捕获音频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64560399/