Module: WavTool
Instance Method Summary collapse
- #ogg_to_wav(oggfile, wavfile = oggfile.sub(/\.ogg$/,'.wav')) ⇒ Object
- #wav_concat(files, save_file = 'audio.wav') ⇒ Object
- #wav_silence(filename, duration: 1) ⇒ Object
Instance Method Details
#ogg_to_wav(oggfile, wavfile = oggfile.sub(/\.ogg$/,'.wav')) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/sra2019.rb', line 54 def ogg_to_wav(oggfile, wavfile=oggfile.sub(/\.ogg$/,'.wav')) if block_given? then yield(oggfile) else `oggdec #{oggfile}` end end |
#wav_concat(files, save_file = 'audio.wav') ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sra2019.rb', line 39 def wav_concat(files, save_file='audio.wav') Writer.new(save_file, Format.new(:stereo, :pcm_16, 22050)) do |writer| files.each do |file_name| Reader.new(file_name).each_buffer(samples_per_buffer=4096) do |buffer| writer.write(buffer) end end end end |
#wav_silence(filename, duration: 1) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sra2019.rb', line 28 def wav_silence(filename, duration: 1) square_cycle = [0] * 100 * duration buffer = Buffer.new(square_cycle, Format.new(:mono, :float, 44100)) Writer.new(filename, Format.new(:mono, :pcm_16, 22050)) do |writer| 220.times { writer.write(buffer) } end end |