Answered by:
Google Chrome Speech API Help

Question
-
allright, i am making a application as a digital life assistant and i am thinking of moving from the awful windows speech recognition over to Google chrome's new speech engine found here
http://slides.html5rocks.com/#speech-input
i have done some research and found it is possible to implement this into .NET, however i havn't been able to do this, what i want is for the user to be able to speak into their microphone and the application detects it and when the user stops speaking it sends what ever they said to google's speech api and then returns just the text result to a textbox inside the program with the highest "confidence" rating.
so far i have been able to achieve the application just as a test on my end to send a .flac file of audio google analyses it and returns:
{"status":0,"id":"10ba02de37960b1fb81ce85d9bd69b7f-1","hypotheses":[{"utterance":"hello how are you today","confidence":0.9641105},{"utterance":"hello how are you to day"}]}
so basically, like i said above, i want to figure out how to code this so that the person simply talks to the app to initiate the dictation to the app, then the app records what they say, and when it detects that the user has stopped speaking and then sends it to the online api and then returns what the highest probability spoken into a textbox within the program.
i found this site that may be some help
http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
thanks guys :)
- JamesTuesday, May 14, 2013 4:48 AM
Answers
-
Thank you
Shane
here you go buddy :), this is one i just whipped together :)
Dim request As HttpWebRequest = DirectCast(HttpWebRequest.Create("https://www.google.com/speech-api/v1/recognize?xjerr=1&client=speech2text&lang=en-US&maxresults=10"), HttpWebRequest) request.Timeout = 60000 request.Method = "POST" request.KeepAlive = True request.ContentType = "audio/x-flac; rate=8000" 'just thought i would let you guys know you need to make this bitrate the EXACT same as your .flac file, it really will cause issues no joke! request.UserAgent = "speech2text" Dim fInfo As New FileInfo(path) Dim numBytes As Long = fInfo.Length Dim data As Byte() Using fStream As New FileStream(path, FileMode.Open, FileAccess.Read) data = New Byte(fStream.Length - 1) {} fStream.Read(data, 0, CInt(fStream.Length)) fStream.Close() End Using Using wrStream As Stream = request.GetRequestStream() wrStream.Write(data, 0, data.Length) End Using Try Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse) Dim resp = response.GetResponseStream() If resp IsNot Nothing Then Dim sr As New StreamReader(resp) MessageBox.Show(sr.ReadToEnd()) resp.Close() resp.Dispose() End If Catch ee As System.Exception MessageBox.Show(ee.Message) End Try
- Edited by J.A.G Productions - James Friday, May 17, 2013 7:45 AM
- Marked as answer by Youen Zen Monday, June 10, 2013 9:05 AM
Friday, May 17, 2013 7:44 AM
All replies
-
I don't know much about "digital life assistants" but I believe a cell phone with large characters or one of those buttons you put around your neck to call for help would be a better alternative.
You've taught me everything I know but not everything you know.
Tuesday, May 14, 2013 6:37 AM -
-
How are you sending google your audio from inside visual studio? You may want to try using the LastIndexOf(string) method. http://msdn.microsoft.com/en-us/library/1wdsy8fy.aspx
somethings like:
If results.Trim().EndsWith("}") Then Dim endPosition AsInteger = results.LastIndexOf("utterance") ' Remove the identified section if it is valid. If endTagStartPosition >= 0 Then results = results.Substring(0, endTagStartPosition) EndIf
From there you would obviously have to strip off all the non characters but thats not too bad. I'm
intersted in finding out how you sent the stuff to google and got a result back, I've been trying to
make that work for a hobby project of mine for a few days now. (home automation)
Shane
Wednesday, May 15, 2013 4:16 PM -
there was a C# example on here somewhere that i converted to vb, ill try and find it again for you, the one im working on new is written in C#Thursday, May 16, 2013 12:44 AM
-
Thank you
Shane
Thursday, May 16, 2013 6:49 AM -
Thank you
Shane
here you go buddy :), this is one i just whipped together :)
Dim request As HttpWebRequest = DirectCast(HttpWebRequest.Create("https://www.google.com/speech-api/v1/recognize?xjerr=1&client=speech2text&lang=en-US&maxresults=10"), HttpWebRequest) request.Timeout = 60000 request.Method = "POST" request.KeepAlive = True request.ContentType = "audio/x-flac; rate=8000" 'just thought i would let you guys know you need to make this bitrate the EXACT same as your .flac file, it really will cause issues no joke! request.UserAgent = "speech2text" Dim fInfo As New FileInfo(path) Dim numBytes As Long = fInfo.Length Dim data As Byte() Using fStream As New FileStream(path, FileMode.Open, FileAccess.Read) data = New Byte(fStream.Length - 1) {} fStream.Read(data, 0, CInt(fStream.Length)) fStream.Close() End Using Using wrStream As Stream = request.GetRequestStream() wrStream.Write(data, 0, data.Length) End Using Try Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse) Dim resp = response.GetResponseStream() If resp IsNot Nothing Then Dim sr As New StreamReader(resp) MessageBox.Show(sr.ReadToEnd()) resp.Close() resp.Dispose() End If Catch ee As System.Exception MessageBox.Show(ee.Message) End Try
- Edited by J.A.G Productions - James Friday, May 17, 2013 7:45 AM
- Marked as answer by Youen Zen Monday, June 10, 2013 9:05 AM
Friday, May 17, 2013 7:44 AM -
Hey what is the variable "path" set to, or what is the coding for it. Thanks JoeTuesday, February 11, 2014 12:13 AM