Permalink
Browse files

Add functionality to play sounds at intervals

  • Loading branch information...
1 parent 275ccca commit 4fadd88384bd000c89ebdf4be479329043f59ae3 Edmore Moyo committed Jun 18, 2012
View
@@ -22,13 +22,12 @@
end
post "/push" do
- text = params[:question]
status = ""
- unless text == ""
+ unless params[:question] == ""
question_id = redis.incr "question:id"
filename = "tmp/#{Digest::SHA1.hexdigest(params.to_s)}.mp3"
redis.rpush("questions", question_id)
- redis.set("question:#{question_id}:text", params[:question])
+ redis.set("question:#{question_id}:text", params[:question].downcase)
redis.set("question:#{question_id}:filename", filename)
espeak(filename, :text => "'#{params[:question]}'")
status = :success
View
@@ -0,0 +1,12 @@
+#container{ font-size: 6em; float: left; }
+#question{
+float: right;
+border: 1px solid #000;
+}
+#question_header{
+background-color: blue;
+text-align: center;
+color: #FFF;
+font-weight: bold;
+}
+#person{ clear: both; }
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -2,17 +2,49 @@ soundManager.url = 'soundmanager/swf/';
soundManager.debugMode = false;
soundManager.onready(function(){
- var mySounds = [];
+ function loop(){
+ setTimeout(function(){
+ var sound = sounds.splice( 0, 1 ),
+ clearDivContents = function( klasses ){
+ console.log( klasses );
+ for( var i=0; i < klasses.length; i+=1 ){
+ $( klasses[i] ).children().detach();
+ }
+ };
- if( sounds.length > 0 ){
- for( var i=0; i < sounds.length; i+=1 ){
- mySounds.push( soundManager.createSound({
- id: sounds[i][0],
- url: "/play?filename=" + sounds[i][1]
- })
- );
+ if( sound.length > 0 ){
+ $("#container").text( sound[0][0] + "?" );
+ console.log( "Playing " + sound[0][1] );
+ var mySound = soundManager.createSound({
+ id: sound[0][0],
+ url: "/play?filename=" + sound[0][1]
+ });
+ mySound.play();
+
+ if ( sound[0][0] === presets[0] ){
+ console.log( "Display random image of person" );
+ $("#person").append( "<img src='images/people/person.jpeg'></img>" );
+ clearDivContents( ["#object"] );
+ }else if ( sound[0][0] === presets[1] ){
+ console.log( "Display random image of object" );
+ $("#object").append( "<img src='images/objects/object.jpeg'></img>" );
+ clearDivContents( ["#person"] );
+ }else{
+ clearDivContents( ["#person", "#object"] );
+ }
+ document.title = "Sound Loop: " + sound[0][0];
+ $("#question_item > ul").append( "<li>" + sound[0][0] + "?" + "</li>" );
+
+ loop();
+ }else{
+ document.title = "Sound Loop: End of Session.";
+ $("#container").text( "End of Session." );
+ clearDivContents( ["#person", "#object"] );
}
- console.log(mySounds);
+ }, 5000);
}
+
+ loop();
+
});
View
@@ -1,5 +1,19 @@
:javascript
- var sounds = #{sounds};
+ var sounds = #{sounds},
+ presets = ["who is this", "what is this"];
+%link{ :rel=>"stylesheet", :type=>"text/css", :href=>"css/start.css" }
%script{:src => "soundmanager/script/soundmanager2.js", :type => "text/javascript"}
%script{:src => "javascripts/start.js", :type => "text/javascript"}
+
+%body>
+ %div{ :id => "container" }
+ Loading .....
+ %div{ :id => "question" }
+ %div{ :id => "question_header" }
+ %span
+ Questions
+ %div{:id => "question_item" }
+ %ul
+ %div{ :id=> "person" }
+ %div{ :id=> "object" }

0 comments on commit 4fadd88

Please sign in to comment.