Created
March 7, 2013 15:04
-
-
Save jensarps/5108653 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var SPEECH = 'speech'; | |
| var bindings = { | |
| /* ... */ | |
| fullSpeed: { | |
| device: SPEECH, | |
| inputId: 'full speed' | |
| }, | |
| stop: { | |
| device: SPEECH, | |
| inputId: 'stop' | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var recognition = new webkitSpeechRecognition(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var recognition = new webkitSpeechRecognition(); | |
| recognition.continuous = true; | |
| recognition.interimResults = true; | |
| recognition.lang = "en_US"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(input.toggleSpeechInput){ | |
| if(speechActive){ | |
| speechHandler.stop(); | |
| } else { | |
| speechHandler.start(); | |
| } | |
| speechActive = !speechActive; | |
| input.toggleSpeechInput = false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please use the unprefixed
SpeechRecognitionif available by adding something like:to
setup_1.jsandsetup_2.js. That way your code won't break when the prefix goes away.