Created
November 3, 2012 17:26
-
-
Save opsb/4008023 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
| Lingal.SayItPlayer = Ember.View.extend({ | |
| game:null, | |
| didInsertElement:function(){ | |
| queue = async.queue(function(job, next){ | |
| job(next); | |
| }, 1); | |
| function wrapped(callback){ | |
| return function(){ | |
| callback(null); | |
| } | |
| } | |
| function say(phrase, language){ | |
| return function(callback){ | |
| console.log("saying " + phrase); | |
| var audio = new Audio("http://tts.lingal.org/?tl=" + language + "&q=" + phrase); | |
| audio.addEventListener('ended', wrapped(callback)); | |
| audio.play(); | |
| } | |
| } | |
| function wait(milliseconds){ | |
| return function(callback){ | |
| console.log("waiting for " + milliseconds + "ms"); | |
| setTimeout(wrapped(callback), milliseconds); | |
| } | |
| } | |
| function promptForSpanish(){ | |
| return function(callback){ | |
| var translation = Lingal.translationsController.random(); | |
| async.series([ | |
| say(translation.get("english"), "en"), | |
| wait(1000), | |
| say(translation.get("spanish"), "es"), | |
| wait(1000), | |
| say(translation.get("spanish"), "es"), | |
| wait(1000) | |
| ], callback); | |
| } | |
| } | |
| function promptForEnglish(){ | |
| return function(callback){ | |
| var translation = Lingal.translationsController.random(); | |
| async.series([ | |
| say(translation.get("spanish"), "es"), | |
| wait(1000), | |
| say(translation.get("english"), "en"), | |
| wait(1000), | |
| ], callback); | |
| } | |
| } | |
| queue.empty = function(){ | |
| queue.push(promptForSpanish()); | |
| } | |
| queue.push(promptForSpanish()); | |
| console.log(this.get("game")); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment