Class: EasyAudioUtils
- Inherits:
-
Object
- Object
- EasyAudioUtils
- Extended by:
- CommandHelper
- Defined in:
- lib/easyaudio_utils.rb
Instance Method Summary collapse
-
#capture(show: false) ⇒ Object
(also: #record)
records audio in mono audio tested with .flac.
- #concat_files(files = []) ⇒ Object (also: #concat)
- #convert ⇒ Object
- #cut(starttime, duration) ⇒ Object
- #duration ⇒ Object
-
#generate_silence(duration) ⇒ Object
silence duration in seconds.
-
#initialize(audio_in = nil, audio_out = 'audio.wav', out: audio_out, working_dir: '/tmp') ⇒ EasyAudioUtils
constructor
A new instance of EasyAudioUtils.
- #play(show: false) ⇒ Object
-
#split(show: false) ⇒ Object
split by silence.
-
#youtube_dl(show: false) ⇒ Object
Download and extract audio from a video on YouTube.
Methods included from CommandHelper
Constructor Details
#initialize(audio_in = nil, audio_out = 'audio.wav', out: audio_out, working_dir: '/tmp') ⇒ EasyAudioUtils
Returns a new instance of EasyAudioUtils.
60 61 62 63 64 65 |
# File 'lib/easyaudio_utils.rb', line 60 def initialize(audio_in=nil, audio_out='audio.wav', out: audio_out, working_dir: '/tmp') @file_in, @file_out, @working_dir = audio_in, out, working_dir end |
Instance Method Details
#capture(show: false) ⇒ Object Also known as: record
records audio in mono audio tested with .flac
70 71 72 73 74 75 76 |
# File 'lib/easyaudio_utils.rb', line 70 def capture(show: false) command = "rec -c 1 -r 8000 -t alsa default #{@file_out} " + "silence 1 0.1 5% 5 1.0 5%" run command, show end |
#concat_files(files = []) ⇒ Object Also known as: concat
78 79 80 |
# File 'lib/easyaudio_utils.rb', line 78 def concat_files(files=[]) WavTool.new(out: @file_out, ).concat files end |
#convert ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/easyaudio_utils.rb', line 84 def convert() if File.extname(@file_in) == '.ogg' then ogg_to_wav() if File.extname(@file_out) == '.wav' end end |
#cut(starttime, duration) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/easyaudio_utils.rb', line 92 def cut(starttime, duration) command = "avconv -i %s -ss %s -t %s %s" % \ [@file_in, starttime, duration, @file_out] run command, show end |
#duration ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/easyaudio_utils.rb', line 100 def duration() case File.extname(@file_in) when '.ogg' OggInfo.open(@file_in).length when '.wav' WavTool.new().duration(@file_in) when '.mp3' Mp3Info.new(@file_in).length end end |
#generate_silence(duration) ⇒ Object
silence duration in seconds
115 116 117 |
# File 'lib/easyaudio_utils.rb', line 115 def generate_silence(duration) WavTool.new(out: @file_out).silence duration: duration end |
#play(show: false) ⇒ Object
121 122 123 124 |
# File 'lib/easyaudio_utils.rb', line 121 def play(show: false) command = "mplayer #{@file_out}" run command, show end |
#split(show: false) ⇒ Object
split by silence
128 129 130 131 132 |
# File 'lib/easyaudio_utils.rb', line 128 def split(show: false) command = "sox -V3 #{@file_in} #{@file_out} silence -l 0 " + " 1 0.5 0.1% : newfile : restart" run command, show end |
#youtube_dl(show: false) ⇒ Object
Download and extract audio from a video on YouTube
By default, Youtube-dl will save the audio in Ogg (opus) format.
138 139 140 141 142 143 144 |
# File 'lib/easyaudio_utils.rb', line 138 def youtube_dl(show: false) command = "youtube-dl -x #{url=@file_in}" command += ' -o ' + @file_out if @file_out run command, show end |