【问题标题】:Capture audio with AMR-NB encoding in UWP?在 UWP 中使用 AMR-NB 编码捕获音频?
【发布时间】:2020-10-27 18:05:08
【问题描述】:

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

结果为@​​987654326@

【问题讨论】:

    标签: c# audio uwp codec amr


    【解决方案1】:

    必须添加这一行来设置“自动预设模式”:

    recordProfile.Audio.Properties.Add(new Guid("23e5cad8-a3fc-4f0f-97c3-dff51d03bc92"), 1.ToString());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-17
      相关资源
      最近更新 更多