使用 NAudio 解码 mu-law 音频
我正在尝试使用 NAudio 将 mu-law 编码音频解码为 pcm 音频。我的服务已发布原始 mu-law 编码音频字节,但我从 NAudio 收到错误,表明数据没有 RIFF 标头。我需要以某种方式添加这个吗?我使用的代码是:
WaveFileReader reader = new WaveFileReader(tmpMemStream);
using (WaveStream convertedStream = WaveFormatConversionStream.CreatePcmStream(reader))
{
WaveFileWriter.CreateWaveFile(recordingsPath + "/" + outputFileName, convertedStream);
}
我还将原始数据保存到磁盘并在 Matlab 中进行解码,这没有问题。谢谢。
I'm attempting to use NAudio to decode mu-law encoded audio into pcm audio. My service is POSTed the raw mu-law encoded audio bytes and I'm getting an error from NAudio that the data does not have a RIFF header. Do I need to add this somehow? The code I'm using is:
WaveFileReader reader = new WaveFileReader(tmpMemStream);
using (WaveStream convertedStream = WaveFormatConversionStream.CreatePcmStream(reader))
{
WaveFileWriter.CreateWaveFile(recordingsPath + "/" + outputFileName, convertedStream);
}
I'm also saving the raw data to the disk and doing the decoding in Matlab which is working with no problem. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您只有原始 mu-law 数据,因此无法在其上使用 WaveFileReader。相反,创建一个继承自 WaveStream 的新类。
在其
Read
方法中,从tmpMemStream返回数据。作为WaveFormat
返回 mu-law WaveFormat。这是您可以使用的通用帮助程序类:
现在您可以像以前一样继续创建转换后的文件,传入 RawSourceWaveStream 作为输入:
Since you just have raw mu-law data, you can't use a WaveFileReader on it. Instead, create a new class that inherits from WaveStream.
In its
Read
method, return data from tmpMemStream. As aWaveFormat
return a mu-law WaveFormat.Here's a generic helper class that you could use:
Now you can proceed to create the converted file as you did before, passing in the RawSourceWaveStream as your input: