Skip to content

Instantly share code, notes, and snippets.

@lmccart
Created March 26, 2015 17:51
Show Gist options
  • Save lmccart/0f8de1a9481c71cb3d87 to your computer and use it in GitHub Desktop.
Save lmccart/0f8de1a9481c71cb3d87 to your computer and use it in GitHub Desktop.
speech api + alchemy
var analyzing = false;
var recognition = new webkitSpeechRecognition();
recognition.onresult = function(event) {
console.log(event)
var text = event.results[0][0].transcript;
if (analyzing == true) {
// check if stop word was said
if (text.indexOf('stop') !== -1) {
analyzing = false;
}
// otherwise analyze
else {
// send it to the alchemy api
// get data back, handle it, etc
}
}
else {
// check if start word was said
if (text.indexOf('start') !== -1) {
analyzing = true;
}
}
}
// you might also try logging errors and stops
recognition.onerror = function(event) {
}
recoginition.onend = function(event) {
}
recognition.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment