c# - 使用UWP以AMR-NB编码捕获音频?

标签 c# audio uwp codec amr

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/

相关文章:

c# - 以编程方式向 SQL Server 添加多个默认值

c# - Entity Framework 代码优先 + mysql System.NullReferenceException 第一次迁移

cocoa - 简单的录音和播放应用程序!

python - 如何在不改变音高的情况下改变音频速度?

xaml - uwp 在样式中定义 eventriggerbehavior

c# - Nuget hell : Cannot reference NuGet package in UWP application due to public key difference

c# - AutoMapper 在投影到可为 null 的枚举时抛出异常

c# - 删除/创建文件在多次迭代后抛出 System.UnauthorizedAccessException

python - 通过python脚本运行ffmpeg命令

c# - 使用 GattCharacteristicNotificationTrigger 在 UWP 中挂起后台任务注册