我正在使用 VB.net 集成将波形文件发送到特定扬声器(正是示例文件中所做的)。但是,我在解码示例文件中实际完成的内容时遇到了麻烦,因为我要查找的内容要简单得多。
将 WAV 文件发送到扬声器的代码是什么 我如何打开和解码所述波形文件?
我发现它比我最初想的更简单。想我会提供自己的答案来帮助其他人寻找相同的信息!
Imports NAudio
公开课形式1
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
结束类