Skip to content

Instantly share code, notes, and snippets.

@erikdubbelboer
Created July 9, 2019 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikdubbelboer/8e98d27a225189768ece7f472202150e to your computer and use it in GitHub Desktop.
Save erikdubbelboer/8e98d27a225189768ece7f472202150e to your computer and use it in GitHub Desktop.
// See: https://bugs.chromium.org/p/chromium/issues/detail?id=799849
var grammar = '#JSGF V1.0; grammar commands; public <command> = left | right | jump | duck ;'
var recognition = new webkitSpeechRecognition();
var speechRecognitionList = new webkitSpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
recognition.continuous = true;
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.maxAlternatives = 1;
recognition.onresult = function(e) {
var command = e.results[e.results.length - 1][0].transcript;
console.log(command);
};
recognition.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment