Skip to content

Instantly share code, notes, and snippets.

@leaysgur
Created January 18, 2018 06:53
Show Gist options
  • Save leaysgur/421f42f9b76449ef826fa55c64a412cd to your computer and use it in GitHub Desktop.
Save leaysgur/421f42f9b76449ef826fa55c64a412cd to your computer and use it in GitHub Desktop.
Continuous recognition by SpeechRecognition API
const recognitions = [];
function R() {
const recognition = new window.SpeechRecognition();
recognition.onresult = function(ev) {
const resultText = ev.results[0][0].transcript;
console.warn(resultText);
};
recognition.onend = function() {
recognitions.push(new R());
};
// all events
[
'onaudioend',
'onaudiostart',
'onerror',
'onnomatch',
'onsoundend',
'onsoundstart',
'onspeechend',
'onspeechstart',
'onstart',
].forEach(evName => {
recognition[evName] = function(ev) {
// console.log(evName, ev);
};
});
recognition.start();
return recognition;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment