Created and presented by Sebastian Schöld
var root = this;
var speechRecognition = root.webkitSpeechRecognition ||
root.mozSpeechRecognition ||
root.msSpeechRecognition ||
root.oSpeechrecognition ||
root.SpeechRecognition;
var recognition = new webkitSpeechRecognition();
// Some configuration
recognition.continuous = true;
recognition.interimResults = true;
recognition.lang = 'en-US';
// Event handlers
recognition.onstart = function() { ... }
recognition.onresult = function(event) { ... }
recognition.onerror = function(event) { ... }
recognition.onend = function() { ... }
recognition.start();
start()
activates the speech recognizeronstart
is called once it begins capturing audioonresult
is called for each set of resultsonend
is called when done recognition.interimResults = true;
var final_transcript = '';
recognition.onresult = function(event) {
var interim_transcript = '';
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;
}
}
};
interimResults - isFinal