Class: CWG::AudioPlayer
- Inherits:
-
Object
- Object
- CWG::AudioPlayer
- Defined in:
- /Users/martyn/cw/cw_clone/lib/cw/audio_player.rb
Constant Summary
- AFPLAY =
'/usr/bin/afplay'
Instance Method Summary (collapse)
- - (Object) audio_dir
- - (Object) convert_book(words)
- - (Object) convert_words(words)
-
- (Object) convert_words_with_ebook2cw(words)
FIXME dry_run.
-
- (Object) play
FIXME dry_run.
- - (Object) play_cmd_for_ps
- - (Object) play_command
- - (Object) play_filename
- - (Object) play_filename_for_ebook2cw
- - (Object) play_tone(tone)
- - (Object) startup_delay
- - (Boolean) still_playing?
- - (Object) stop
- - (Object) temp_filename_for_ebook2cw
- - (Object) tone
Instance Method Details
- (Object) audio_dir
23 24 25 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 23 def audio_dir Params.audio_dir ||= './audio' end |
- (Object) convert_book(words)
31 32 33 34 35 36 37 38 39 40 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 31 def convert_book words words = words.delete("\n") File.open(temp_filename_for_ebook2cw, 'w') do |file| file.print words end cl = Cl.new.cl_full(temp_filename_for_ebook2cw) ! @dry_run ? `#{cl}` : cl File.delete(temp_filename_for_ebook2cw) File.rename(play_filename_for_ebook2cw + '0000.mp3', play_filename_for_ebook2cw) end |
- (Object) convert_words(words)
50 51 52 53 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 50 def convert_words words tone.generate words unless Params.use_ebook2cw convert_words_with_ebook2cw words if Params.use_ebook2cw end |
- (Object) convert_words_with_ebook2cw(words)
FIXME dry_run
43 44 45 46 47 48 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 43 def convert_words_with_ebook2cw words words = words.delete("\n") cl = Cl.new.cl_echo(words) ! @dry_run ? `#{cl}` : cl File.rename(play_filename + '0000.mp3', play_filename) end |
- (Object) play
FIXME dry_run
61 62 63 64 65 66 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 61 def play puts 'here' cmd = play_command + ' ' + play_filename @pid = ! @dry_run ? Process.spawn(cmd) : cmd Process.waitpid(@pid) end |
- (Object) play_cmd_for_ps
80 81 82 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 80 def play_cmd_for_ps '[' << play_command[0] << ']' << play_command[1..-1] end |
- (Object) play_command
15 16 17 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 15 def play_command @play_command ||= AFPLAY end |
- (Object) play_filename
55 56 57 58 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 55 def play_filename return play_filename_for_ebook2cw if Params.use_ebook2cw tone.play_filename end |
- (Object) play_filename_for_ebook2cw
19 20 21 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 19 def play_filename_for_ebook2cw @play_filename ||= File.(Params.audio_filename, audio_dir) end |
- (Object) play_tone(tone)
76 77 78 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 76 def play_tone tone `#{play_command + ' ' + tone}` end |
- (Object) startup_delay
90 91 92 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 90 def startup_delay 0.2 end |
- (Boolean) still_playing?
84 85 86 87 88 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 84 def ps = `ps -ewwo pid,args | grep #{play_cmd_for_ps}` return ps.include? "#{play_filename_for_ebook2cw}" if Params.use_ebook2cw return ps.include? tone.play_filename unless Params.use_ebook2cw end |
- (Object) stop
68 69 70 71 72 73 74 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 68 def stop begin Process.kill(:TERM, @pid) Process.wait(@pid) rescue end end |
- (Object) temp_filename_for_ebook2cw
27 28 29 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 27 def temp_filename_for_ebook2cw File.("tempxxxx.txt", audio_dir) end |
- (Object) tone
11 12 13 |
# File '/Users/martyn/cw/cw_clone/lib/cw/audio_player.rb', line 11 def tone @tone ||= ToneGenerator.new end |