javascript - Unable to collect results HTML5 speech recognition API -
i using speech recognition api unable retrieve results whenever it's done.
here piece of code using:
var recognition = new webkitspeechrecognition(); recognition.continuous = true; recognition.interimresults = true; recognition.onresult = function(event) { console.log(event) }
this outputs (in console):
bubbles: false cancelbubble: false cancelable: false clipboarddata: undefined currenttarget: speechrecognition defaultprevented: false emma: null eventphase: 0 interpretation: null path: nodelist[0] resultindex: 0 results: speechrecognitionresultlist returnvalue: true srcelement: speechrecognition target: speechrecognition timestamp: 1408325350996 type: "result" __proto__: speechrecognitionevent
i can't wrap head around it. how retrieve results?
the result in results
list in returned event. can find sample code access here:
http://updates.html5rocks.com/2013/01/voice-driven-web-apps-introduction-to-the-web-speech-api
recognition.onresult = function(event) { var interim_transcript = ''; (var = event.resultindex; < event.results.length; ++i) { if (event.results[i].isfinal) { final_transcript += event.results[i][0].transcript; } else { interim_transcript += event.results[i][0].transcript; } } final_transcript = capitalize(final_transcript); final_span.innerhtml = linebreak(final_transcript); interim_span.innerhtml = linebreak(interim_transcript); }; }
Comments
Post a Comment