Skip to content

Instantly share code, notes, and snippets.

@jeshuamaxey
Created June 9, 2013 09:44
Show Gist options
  • Save jeshuamaxey/5742977 to your computer and use it in GitHub Desktop.
Save jeshuamaxey/5742977 to your computer and use it in GitHub Desktop.
This is the bare minimum code to get voice dictation up and running with Chrome's new speech recognition API. Copy and paste into the JavaScript console, call the function and away you go.
function setupDictation() {
var recognizer = new webkitSpeechRecognition();
recognizer.continuous = true;
recognizer.interimResults = true;
recognizer.onresult = function(e) {
if (e.results.length) {
var lastResultIdx = e.resultIndex;
var message = e.results[lastResultIdx][0].transcript;
if(e.results[lastResultIdx].isFinal) {
console.log(message);
}
}
};
recognizer.onend = function(e) {
console.log('dictation ended');
};
recognizer.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment