Execute this code on page load and you'll see a permissions dialogue asking you to grant microphone access. Click allow and speech to text recognition will begin. Check the speech recognition API docs for events you can bind to.
var interim_result, final_result;
var recognition_engine = new webkitSpeechRecognition();
recognition_engine.continuous = true;
recognition_engine.interimResults = true;
recognition_engine.lang = 'en-US';
recognition_engine.onresult = function(function(e) {
var result, i;
interim_result = '';
if (typeof e.results === 'undefined') {
recognition_engine.stop();
console.log('SPEECH RECOGNITION : stopping due to empty result.', e);
return;
}
for (i = event.resultIndex; i < event.results.length; ++i) {
result = event.results[i];
if (result.isFinal) {
final_result = result[0].transcript;
console.log('SPEECH RECOGNITION : final transcript = ' + final_result, e);
// trigger a command matching the final utterance here
} else {
interim_result += result[0].transcript;
}
}
console.log('SPEECH RECOGNITION : interim result = ' + interim_result);
};
recognition_engine.start();