直接从WAV文件发送到DirectShow声卡

时间:2013-05-20 20:53:19

标签: .net vb.net naudio

我正在使用VB.net集成向特定发言人发送波形文件(具体在示例文件中完成的操作)。但是,我无法解码样本文件中实际完成的内容,因为我正在寻找的内容要简单得多。

将WAV文件发送到扬声器的代码是什么?如何打开和解码所述波形文件?

1 个答案:

答案 0 :(得分:0)

我认为它比原先想象的要简单。想我会提供自己的答案来帮助其他人寻找相同的信息!

Imports NAudio

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim wavefile As New NAudio.Wave.Mp3FileReader("C:\Users\iqm2admin\Desktop\Pause.mp3") 'The Audio MP3 file you want to play
    Dim waveout As New NAudio.Wave.WaveOut() 'Create Wave Object
    Dim devicecount As Integer = NAudio.Wave.WaveOut.DeviceCount() 'Count the devices
    Dim TestString As String = "Speaker description" 'The desciption of the speaker you want to play to
    Dim SDevice As String = Nothing
    Dim DeviceNum As Integer
    For i As Integer = 0 To devicecount - 1
        SDevice = NAudio.Wave.WaveOut.GetCapabilities(i).ProductName
        If TestString.ToLower = SDevice.ToLower Then                   'Find the speaker you want to play to
            DeviceNum = i
        End If
    Next
    waveout.DeviceNumber = DeviceNum ' set the device to play to
    waveout.Init(wavefile)
    waveout.Play() 'play the file
End Sub

结束班