class Saytime
the files were then manually split into wav files using the sound editing software called Audacity
Public Class Methods
new(filepath='')
click to toggle source
# File lib/saytime.rb, line 24 def initialize(filepath='') @filepath = filepath Dir.chdir filepath unless filepath.empty? end
Public Instance Methods
now(wav_player='play')
click to toggle source
# File lib/saytime.rb, line 31 def now(wav_player='play') make_wav() `#{wav_player} time.wav` end
Private Instance Methods
append_wavs(wav_files, target_wav)
click to toggle source
# File lib/saytime.rb, line 40 def append_wavs(wav_files, target_wav) lib = File.dirname(__FILE__) Writer.new(target_wav, Format.new(:stereo, :pcm_16, 44100)) do |writer| wav_files.each do |name| file_name = @filepath.empty? ? File.join(lib,'..','wav',name) : \ File.join(@filepath, name) Reader.new(file_name).each_buffer(samples_per_buffer=4096) do |buffer| writer.write(buffer) end end end end
make_wav()
click to toggle source
# File lib/saytime.rb, line 61 def make_wav() a = ['the_time_is'] h, m, meridiem = Time.now.strftime("%-I %M %P").split a << h a.concat (m.length > 1 and m[0] != '1' ? [m[0] + '0', m[1]] : [m]) a << meridiem a.reject!{|x| x =~ /^0/} append_wavs(a.map{|x| x + '.wav'}, 'time.wav') end