Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Setting up peekaboo to support Mac OS X

  • Loading branch information...
commit ff1a57d67c9669e32a02bde619e3b8e1a308fad3 1 parent 920f310
@edmore authored
Showing with 23 additions and 7 deletions.
  1. +1 −1  .gitignore
  2. +7 −2 README
  3. +14 −4 peekaboo.rb
  4. +1 −0  tmp/README
View
2  .gitignore
@@ -3,4 +3,4 @@
dump.rdb
.directory
.rvmrc
-tmp/*
+tmp/*.mp3
View
9 README
@@ -1,2 +1,7 @@
-Toy App for experimenting with Redis queuing and Text to speech synthesis.
-Coded in Sinatra and JS. Redis and Espeak as dependencies. In browser playback using Sound Manager.
+Toy App for my daughter. Experimenting with Redis queuing and Text to speech synthesis.
+Coded in Sinatra and JS. In browser playback using Sound Manager.
+
+Dependencies:
+Redis
+say and lame - Mac OS X
+espeak and lame - Linux
View
18 peekaboo.rb
@@ -14,6 +14,10 @@ def sanitize_dir_entries( dir )
entries.select{ |x| (x != ".." && x != ".") }
end
+def command?(command)
+ system("which #{command} > /dev/null 2>&1")
+end
+
get "/" do
haml :index
end
@@ -30,11 +34,17 @@ def sanitize_dir_entries( dir )
status = ""
unless params[:question] == ""
question_id = redis.incr "question:id"
- filename = "tmp/#{Digest::SHA1.hexdigest(params.to_s)}.mp3"
+ name = "tmp/#{Digest::SHA1.hexdigest(params.to_s)}"
+ filename = "#{name}.mp3"
redis.rpush("questions", question_id)
redis.set("question:#{question_id}:text", params[:question].downcase)
redis.set("question:#{question_id}:filename", filename)
- espeak(filename, :text => "'#{params[:question]}'")
+ if(command?("say"))
+ cmd = "say -v Vicki '#{params[:question]}' -o #{name}.aiff && lame --quiet #{name}.aiff #{name}.mp3 && rm -f #{name}.aiff"
+ system(cmd) # Mac OS X
+ else
+ espeak(filename, :text => "'#{params[:question]}'") # Linux
+ end
status = :success
end
redirect "/push?status=#{status}"
@@ -57,8 +67,8 @@ def sanitize_dir_entries( dir )
get "/clear" do
redis.flushall
- system("rm -rf tmp/*")
- [200, {'Content-type' => 'text/plain'},"Session Cleared"]
+ system("rm -rf tmp/*.mp3")
+ [200, {'Content-type' => 'text/plain'},"Session Cleared - [Audio files removed]."]
end
get "/play" do
View
1  tmp/README
@@ -0,0 +1 @@
+Temp folder for audio files

0 comments on commit ff1a57d

Please sign in to comment.
Something went wrong with that request. Please try again.