正如标题所说,我正在尝试使用 vb.net 2010 和 NAudio 库实时存储和播放麦克风数据。我从 NAudio Codeplex 网站获得了 C# 代码,并在 vb.net 中进行了翻译。代码中没有错误并且程序可以正常工作(我放置了一个计数器,每次麦克风数据可用时都会不断增加和更新标签,以查看它是否真的在工作),但我什么也听不到。
这是代码
进口 NAudio 导入 System.IO
'我正在使用的库Private Sub wi_dataAvailable(ByVal obj As Object, ByVal e As Wave.WaveInEventArgs) 处理 wi.DataAvailable count += 1 '这里是计数器增加的地方 Label1.Text = count '并且这里的标签被更新,它似乎工作正常 play_packet(e.Buffer) 结束子
Private Sub play_packet(ByVal DR() As Byte) Dim MS As New MemoryStream(DR) Dim frmt As New Wave.WaveFormat frmt = Wave.WaveFormat.CreateALawFormat(8000, 1) Dim rsws As New Wave.RawSourceWaveStream(MS, frmt) Dim pcms As Wave.WaveStream = Wave.WaveFormatConversionStream.CreatePcmStream(rsws) Dim m_bwp As New Wave.BufferedWaveProvider(New Wave.WaveFormat(8000, 16, 1)) Dim dec() As Byte = cnssb(pcms) m_bwp.AddSamples(dec, 0, dec.Length) Dim latency As Integer Dim cbi As Wave.WaveCallbackInfo = Wave.WaveCallbackInfo.NewWindow Dim out_dev As New Wave.WaveOut(cbi) out_dev.DesiredLatency = latency out_dev.Init(m_bwp) out_dev.Play() End Sub Private Function cnssb(ByVal nss As Wave.WaveStream) As Byte() Dim memstr As New MemoryStream Dim buff(1024) As Byte Dim bytes As Integer bytes = nss.Read(buff, 0, buff.Length) While bytes > 0 memstr.Write(buff, 0, bytes) bytes = nss.Read(buff, 0, buff.Length) End While Dim by() As Byte = memstr.ToArray Return by End Function
希望你能帮我!