Had an itch to try out the Web Speech API. I copied the code exactly from the article, and I'm having an issue where you speak, but nothing happens until you speak AGAIN.
[Fiddle: http://jsfiddle.net/w75v2tm5/]
JS:
if (!('webkitSpeechRecognition' in window)) {
//handle error stuff here...
} else {
var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = false;
recognition.start();
var final_transcript = '';
recognition.onresult = function (event) {
var interim_transcript = '';
if (typeof (event.results) == 'undefined') {
recognition.onend = null;
recognition.stop();
upgrade();
return;
}
for (var i = event.resultIndex; i < event.results.length; ++i) {
if (event.results[i].isFinal) {
final_transcript += event.results[i][0].transcript;
} else {
interim_transcript += event.results[i][0].transcript;
}
}
document.getElementsByTagName('div')[0].innerText = final_transcript;
};
}
For example, if I were to say "Hello world", the <div> I have set up to display the results would not display "Hello world" until I said something else, or made a sound. But if I said something else, THAT would not be displayed until I said something else AGAIN.
The variable "final_transcript" is holding the PREVIOUS result, and not what I just said. It's off by just 1.
To give you a better idea...
Me: "Hello world"
final_transcript = '';
[Wait...]
Me: "Test"
final_transcript = 'Hello world'
And this just continues. The code is failing to transcribe what I am saying AS I am saying it. Very weird.
Any thoughts as to why this could be?