如何解码 RTP 数据包并将其保存为 .wav 文件
我正在尝试开发一个应用程序,在其中建立 sip 呼叫,然后捕获 rtp 音频数据包。由于它们是编码的,所以我需要解码它们并将其保存为 .wav 文件。尝试使用 NAudio 但没有成功。有没有使用 NAudio 或任何其他来源来解决这个问题的解决方案...
我使用的代码如下。 data是rtp包数据所在的字节数组。
System.IO.MemoryStream stream = new System.IO.MemoryStream(data);
RawSourceWaveStream rsws = new RawSourceWaveStream(stream, WaveFormat.CreateMuLawFormat(8000,1));
WaveStream conversionStream = WaveFormatConversionStream.CreatePcmStream(rsws);
WaveStream blockAlignedStream = new BlockAlignReductionStream(conversionStream);
byte[] buffer = new byte[udpHeader.Data.Length];
blockAlignedStream.Read(buffer, 0, udpHeader.Data.Length);
writer.WriteData(buffer, 0, buffer.Length);
提前致谢。
I am trying to develop an application in which a sip call is established and then i am capturing rtp audio packets. As they are encoded so i need to decode them and save it has .wav file. Tried using NAudio but didnt worked. Is there any solution using NAudio or any other source to solve this problem...
the code i used is as follow. data is the byte array in which rtp packet data is.
System.IO.MemoryStream stream = new System.IO.MemoryStream(data);
RawSourceWaveStream rsws = new RawSourceWaveStream(stream, WaveFormat.CreateMuLawFormat(8000,1));
WaveStream conversionStream = WaveFormatConversionStream.CreatePcmStream(rsws);
WaveStream blockAlignedStream = new BlockAlignReductionStream(conversionStream);
byte[] buffer = new byte[udpHeader.Data.Length];
blockAlignedStream.Read(buffer, 0, udpHeader.Data.Length);
writer.WriteData(buffer, 0, buffer.Length);
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
迟到总比不到好!
使用 Mark Heath 提供的以下辅助类
从
使用 NAudio 解码 mu-law 音频
获取最新的 NAudio.dll和 NAudio.WindowsMediaFormat.dll
来自
http://naudio.codeplex.com/
然后执行以下操作将 U-Law 或 Mu-Law 转换为 Wav:
请记住尊重这些音频文件所有者的隐私!
Better late than never!
Use the following helper classs by Mark Heath
from
Using NAudio to decode mu-law audio
Get the latest NAudio.dll and NAudio.WindowsMediaFormat.dll
from
http://naudio.codeplex.com/
Then do the following to convert from U-Law or Mu-Law to Wav:
Just remember to respect the privacy of the owners of those audio files!