class CW::AudioPlayer

Public Instance Methods

convert_book(words) click to toggle source
# File lib/cw/audio_player.rb, line 46
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
convert_words(words) click to toggle source
# File lib/cw/audio_player.rb, line 64
def convert_words words
  tone.generate words if Cfg.config["use_ebook2cw"].nil?
  convert_words_with_ebook2cw words if Cfg.config["use_ebook2cw"]
end
convert_words_with_ebook2cw(words) click to toggle source
# File lib/cw/audio_player.rb, line 57
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
os_play_command() click to toggle source
# File lib/cw/audio_player.rb, line 17
def os_play_command
  if is_mac?
    'afplay'
  elsif is_posix?
    'ossplay'
  else
    puts 'Error - play_command required in .cw_config'
    exit 1
  end
end
play() click to toggle source
# File lib/cw/audio_player.rb, line 74
def play
  cmd = play_command + ' ' + play_filename
  @pid = ! @dry_run ? Process.spawn(cmd) : cmd
  begin
    Process.waitpid(@pid) if @pid.is_a?(1.class)
  rescue Errno::ECHILD
  end
end
play_cmd_for_ps() click to toggle source
# File lib/cw/audio_player.rb, line 95
def play_cmd_for_ps
  '[' << play_command[0] << ']' << play_command[1..-1]
end
play_command() click to toggle source
# File lib/cw/audio_player.rb, line 28
def play_command
  if Cfg.config["play_command"].nil?
    Cfg.config.params["play_command"] =
      os_play_command
  end
  Cfg.config["play_command"]
end
play_filename() click to toggle source
# File lib/cw/audio_player.rb, line 69
def play_filename
  return play_filename_for_ebook2cw if Cfg.config["use_ebook2cw"]
  tone.play_filename
end
play_filename_for_ebook2cw() click to toggle source
# File lib/cw/audio_player.rb, line 36
def play_filename_for_ebook2cw
  @play_filename ||= File.join(audio_dir, audio_filename)
  puts "@play_filename = #{@play_filename}"
  @play_filename
end
play_tone(tone) click to toggle source
# File lib/cw/audio_player.rb, line 91
def play_tone tone
  `#{play_command + ' ' + tone}`
end
still_playing?() click to toggle source
# File lib/cw/audio_player.rb, line 99
def still_playing?
  cl = "ps -eo  pid,args | grep #{play_cmd_for_ps}"
  ps = `#{cl}`
  return ps.include?("#{play_filename_for_ebook2cw}") if Cfg.config["use_ebook2cw"]
  return ps.include?(tone.play_filename) unless Cfg.config["use_ebook2cw"]
end
stop() click to toggle source
# File lib/cw/audio_player.rb, line 83
def stop
  begin
    Process.kill(:TERM, @pid)
    Process.wait(@pid)
  rescue
  end
end
temp_filename_for_ebook2cw() click to toggle source
# File lib/cw/audio_player.rb, line 42
def temp_filename_for_ebook2cw
  File.expand_path("tempxxxx.txt", audio_dir)
end
tone() click to toggle source
# File lib/cw/audio_player.rb, line 13
def tone
  @tone ||= ToneGenerator.new
end