Skip to content

Instantly share code, notes, and snippets.

@jensarps
Created March 7, 2013 15:04
Show Gist options
  • Save jensarps/5108653 to your computer and use it in GitHub Desktop.
Save jensarps/5108653 to your computer and use it in GitHub Desktop.
var SPEECH = 'speech';
var bindings = {
/* ... */
fullSpeed: {
device: SPEECH,
inputId: 'full speed'
},
stop: {
device: SPEECH,
inputId: 'stop'
}
}
var resultHandler = function (evt) {
var requiredConfidence = 0.75;
for (var i = evt.resultIndex; i < evt.results.length; ++i) {
var result = evt.results[i],
primary = result[0];
if (result.isFinal || primary.confidence > requiredConfidence) {
var transcript = primary.transcript;
console.log('We have a match:', transcript);
}
}
};
var recognition = new webkitSpeechRecognition();
var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = true;
recognition.lang = "en_US";
inputController = new InputController(bindings);
inputController.registerDeviceHandler(SpeechHandler, 'speech');
speechHandler = inputController.deviceHandlers.speech;
speechHandler.requiredConfidence = 0.8;
speechHandler.onRecognitionEnded = function(){
// do stuff, e.g. notify user that recognition is inactive
speechActive = false;
};
if(input.toggleSpeechInput){
if(speechActive){
speechHandler.stop();
} else {
speechHandler.start();
}
speechActive = !speechActive;
input.toggleSpeechInput = false;
}
@jankeromnes
Copy link

Please use the unprefixed SpeechRecognition if available by adding something like:

var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
var recognition = new SpeechRecognition();

to setup_1.js and setup_2.js. That way your code won't break when the prefix goes away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment