播放 g711 a-law 流时声音断断续续 [英] Choppy sound on playing g711 a-law stream

查看:149
本文介绍了播放 g711 a-law 流时声音断断续续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的一个项目中使用 naudio 时遇到问题 - 很可能我只是忽略了一个小错误,但我没有发现它,所以我可以请求一些帮助.

I have an issue using naudio for a project of mine - most likely I just overlooked a tiny error, but I don't catch it, so may I kindly ask for some help.

我正在开展一个项目,以接收(并进一步处理)我通过网络接收的音频流.该流使用 G.711 a-law 使用 8kHz 和 8bit 进行编码,并以 20 毫秒(或每秒 50 个数据包)的微小片段发送.

I am working on a project to receive (and further work with) an audio stream I receive over a network. The stream is encoded with G.711 a-law using 8kHz and 8bit and sent in tiny pieces of 20ms (or 50 packets per second).

以下代码通过 UDP 接收流(基本上每当接收到 UDP 数据包时,它就会从套接字中读取并添加到 naudio BufferedWaveProvider:

The following code receives the stream via UDP (basically whenever a UDP packet is received, it is read from the socket and added to the naudio BufferedWaveProvider:

Private Provider As New NAudio.Wave.BufferedWaveProvider(NAudio.Wave.WaveFormat.CreateALawFormat(8000, 1))
Private Sub FT636VOIP_U_Auslesen(ByVal ar As IAsyncResult)
    sample = FT636VOIPUSocket.EndReceive(ar, New Net.IPEndPoint("10.48.11.43", 60001))
    Provider.AddSamples(sample, 0, sample.Count)
    FT636VOIPUSocket.BeginReceive(New AsyncCallback(AddressOf FT636VOIP_U_Auslesen), FT636VOIPUSocket)
End Sub

在另一个线程中启动(以避免阻塞主应用程序),WaveOutEvent 与 BufferedWaveProvider 链接以进行播放.

Being started in another thread (to avoid blocking the main application), a WaveOutEvent is linked with the BufferedWaveProvider for playback.

Private Sub Audio()
    Dim wo As New NAudio.Wave.WaveOutEvent
    wo.DesiredLatency = 1000
    wo.Init(Provider)
    wo.Play()
    Do While wo.PlaybackState = NAudio.Wave.PlaybackState.Playing
        Threading.Thread.Sleep(500)
    Loop
End Sub

好吧,网络连接已启动并迅速填充缓冲区,并在所需的延迟后开始播放,但只会产生断断续续的声音",尽管本质上应该只有静音...

Well, the network connection is up and quickly filling the Buffer and the playback starts after the desired latency but only creates a 'choppy sound', though essentially there should only be silence...

我是否必须在某个阶段对流进行解码(尽管 BufferedWaveProvider 已使用正确的编码进行初始化?或者我是否遗漏了其他内容...

Do I have to decode the stream at some stage (though the BufferedWaveProvider is initialized with the correct coded? Or do I miss something else...

推荐答案

如果您在音频到达时对其进行解码并将其作为 16 位音频放入 BufferedWaveProvider 中,您将获得最佳结果.另外,您确定正在接收的网络数据包中没有周围的元数据吗?如果是这样就需要去掉,否则会产生噪音.

You will get best results if you decode the audio as it arrives and put it into the BufferedWaveProvider as 16 bit audio. Also, are you sure that there is no surrounding metadata in the network packets being received? If so that needs to be stripped out or it will result in noise.

NAudio 演示项目包含此确切场景的示例,因此如果您需要进一步帮助,可以将其用作参考.

The NAudio demo project contains an example of this exact scenario, so you can use that as a reference if you need further help.

这篇关于播放 g711 a-law 流时声音断断续续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆