我找不到Google Cloud speech API来使用vb.net将.wav文件转录成.txt文件。
身份验证正在工作:
AuthExplicit2("AudioTranscription", "C:\AudioTranscription\GoogleAuthentication\GoogleTranscriptionAuthentication.json")我试过寻找代码示例作为模板,但我就是搞不懂代码。有人能帮我吗?
Try
Dim fileStream As FileStream = File.OpenRead("C:\AudioTranscription\Audio\dictation-partial.flac")
'Dim memoryStream As MemoryStream = File.OpenWrite("C:\AudioTranscription\Audio\dictation-partial.flac")
'Dim memoryStream As MemoryStream = New MemoryStream("C:\AudioTranscription\Audio\dictation-partial.txt")
memoryStream.SetLength(fileStream.Length)
fileStream.Read(memoryStream.GetBuffer(), 0, CInt(fileStream.Length))
Dim BA_AudioFile As Byte() = memoryStream.GetBuffer()
Dim _HWR_SpeechToText As HttpWebRequest = Nothing
'_HWR_SpeechToText = CType(HttpWebRequest.Create("https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=YOUR_API_KEY_HERE"), HttpWebRequest)
_HWR_SpeechToText.Credentials = CredentialCache.DefaultCredentials
_HWR_SpeechToText.Method = "POST"
_HWR_SpeechToText.ContentType = "audio/x-flac; rate=44100"
_HWR_SpeechToText.ContentLength = BA_AudioFile.Length
Dim stream As Stream = _HWR_SpeechToText.GetRequestStream()
stream.Write(BA_AudioFile, 0, BA_AudioFile.Length)
stream.Close()
Dim HWR_Response As HttpWebResponse = CType(_HWR_SpeechToText.GetResponse(), HttpWebResponse)
If HWR_Response.StatusCode = HttpStatusCode.OK Then
Dim SR_Response As StreamReader = New StreamReader(HWR_Response.GetResponseStream())
Console.WriteLine(SR_Response.ReadToEnd())
End If
Catch ex As Exception
Console.WriteLine(ex.ToString())
End Try
Console.ReadLine()
imgAudioFile.Visible = True发布于 2018-08-02 03:30:37
public documentation中的代码需要client libraries或生成post request。在使用post请求时,您应该将音频文件上传到Cloud Storage,以便根据文档使用请求中的url,而不是使用本地文件。关于POST请求,您可以基于this post在post请求上发送JSON body。
https://stackoverflow.com/questions/51485865
复制相似问题