You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用CSCore录制麦克风音频如何输出16kHz单声道PCM格式WAV文件

解决方案

你需要在音频采集流输出后、写入文件前插入格式转换逻辑,借助CSCore内置的MediaFoundationResampler即可自动完成采样率转换、声道数合并、编码格式转换的全部操作,具体修改位置如下:

  1. 找到原有代码中如下片段:
var singleBlockNotificationStream = new SingleBlockNotificationStream(soundInSource.ToSampleSource());
m_FinalSource = singleBlockNotificationStream.ToWaveSource();

m_Writer = new WaveWriter("output.wav", m_FinalSource.WaveFormat);
  1. 替换为以下代码,插入你定义的need_wave_format做转换目标:
var singleBlockNotificationStream = new SingleBlockNotificationStream(soundInSource.ToSampleSource());
// 用你定义的目标格式做重采样转换
var resampler = MediaFoundationResampler.Create(singleBlockNotificationStream.ToWaveSource(), need_wave_format);
m_FinalSource = resampler;

m_Writer = new WaveWriter("output.wav", m_FinalSource.WaveFormat);

说明

  • MediaFoundationResampler会自动处理:原始IEEE Float编码转16位PCM、立体声转单声道、原始采样率转16kHz的所有逻辑,无需额外手动处理音频帧。
  • 原有停止录制时的资源释放逻辑不需要修改,resampler已经赋值给m_FinalSource,会在停止时跟着一起释放。

内容的提问来源于stack exchange,提问作者Артем Смолин

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 05:48:00