Skip to content

Instantly share code, notes, and snippets.

@opsb
Created November 3, 2012 17:26
Show Gist options
  • Select an option

  • Save opsb/4008023 to your computer and use it in GitHub Desktop.

Select an option

Save opsb/4008023 to your computer and use it in GitHub Desktop.
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