Created
December 9, 2012 15:53
-
-
Save mvilrokx/4245721 to your computer and use it in GitHub Desktop.
Iris: Function called when a speech recognition result is received.
This file contains 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
# Function called when a speech recognition result is received. | |
speechChange = (e) -> | |
# Flow | |
# 1. pass received text to service that can interpret the text (using WolframAlpha right now) | |
# 2. when this service returns, show results of this service in the stream | |
e.preventDefault() | |
if e.type == 'webkitspeechchange' && e.originalEvent.results | |
topResult = e.originalEvent.results[0] | |
adjustStream(topResult.utterance) | |
# submit the form to the proxy service | |
$.get( | |
$('#process_speech').attr('action'), | |
$('#process_speech').serialize(), | |
# (data, textStatus, jqXHR) -> adjustStream(data.queryresult.pod[1].subpod.plaintext), | |
(data, textStatus, jqXHR) -> | |
if data.queryresult.success == 'true' | |
if data.queryresult.pod[1].subpod instanceof Array | |
adjustStream(img(data.queryresult.pod[1].subpod[0].img)) | |
else | |
adjustStream(img(data.queryresult.pod[1].subpod.img)) | |
else | |
adjustStream("I'm sorry, I didn't understand, please try again") | |
"json" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment