I cannot figure out the Google cloud speech API to transcribe a .wav file to a .txt file using vb.net. The authentication is working with line: AuthExplicit2("AudioTranscription", "C:\AudioTranscription\GoogleAuthentication\GoogleTranscriptionAuthentication.json")
I have tried finding code examples to use as a template but i just can't figure out the code. Can anyone help me with this?
I have tried finding code examples to use as a template but i just can't figure out the code. Can anyone help me with this?
VB.NET:
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