c# - 在 UWP 中使用 AMR-NB 编码捕获音频?
问题描述
在支持的编解码器页面上,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# - 如何使用 ODBC 在 .NET Core 中连接 Sybase 17 ASA?
- solr - 错误:产品上的 solr 更新索引
- javascript - 数字范围的正则表达式约束,限制为小数点后 3 位
- javascript - 将 ID 从 Foreach 传递到 Html.BeginForm
- python - 如何使用 python SQL api 在 cosmosDB 中进行批量插入
- reactjs - 如何将垂直滚动条向右移动?
- sql - 获得首要列主要,次要,三级以消除重复
- api - GoCD 通过 API 取消阶段返回“找不到您请求的资源!”
- solace - Apache camel / Java 客户端如何安全地连接到主题端点
- go - 使用 go 代码从 Kubernetes 连接到外部 Kubernetes 集群