Visual Basic将字符串转换为音频(WAV)文件并播放

时间:2019-01-21 13:23:54

标签: vb.net winforms basic

我正在使用VB获胜表格,需要从字符串中播放波形,但是我不知道该怎么做。

Dim URl As String ="http://localhost/main.php?command=readdata"
Dim request As HttpWebRequest = HttpWebRequest.Create(URl)
request.Proxy = Nothing
request.UserAgent = "Test"
Dim response As HttpWebResponse = request.GetResponse
Dim responseStream As System.IO.Stream = response.GetResponseStream

Dim Reader As New System.IO.StreamReader(responseStream)
Dim data As String = Reader.ReadToEnd
Reader.Close()

Dim AudioData As String = Hex2String(data)

'here i wont play and save this data 

1 个答案:

答案 0 :(得分:0)

您不想将数据作为字符串读取,因为它不是字符串。 WAV数据是二进制数据。它作为字符串毫无意义,如果将其编码为字符串,则可能会丢失一些数据。因此,如果不将其转换为字符串,则根本不需要StreamReader。只需创建一个新文件作为流,然后将一个流中的所有字节复制到另一个流中即可:

Dim url As String ="http://localhost/main.php?command=readdata"
Dim request As HttpWebRequest = HttpWebRequest.Create(url)
request.Proxy = Nothing
request.UserAgent = "Test"
Dim response As HttpWebResponse = request.GetResponse()
Using responseStream As Stream = response.GetResponseStream()
    Using fileStream As New New FileStream("MyFile.wav", FileMode.CreateNew)
        responseStream.CopyTo(fileStream)
    End Using
End Using