Class: WaveToJson::Audio
- Inherits:
-
Object
- Object
- WaveToJson::Audio
- Defined in:
- lib/wave_to_json/audio.rb
Constant Summary collapse
- MAX_VALUE =
2**16
- MIN_VALUE =
-(2**16)
Instance Method Summary collapse
- #duration ⇒ Object
- #generate_raw_file(raw_file_path, options = {}) ⇒ Object
-
#initialize(audio_path) ⇒ Audio
constructor
A new instance of Audio.
- #number_of_channels ⇒ Object
- #raw_data(options = {}) ⇒ Object
Constructor Details
#initialize(audio_path) ⇒ Audio
Returns a new instance of Audio.
6 7 8 |
# File 'lib/wave_to_json/audio.rb', line 6 def initialize(audio_path) @path = audio_path end |
Instance Method Details
#duration ⇒ Object
10 11 12 13 |
# File 'lib/wave_to_json/audio.rb', line 10 def duration return @duration if @duration @duration = ShellCommand.new(['soxi', '-D', @path]).run_and_return_output_if_success.to_f end |
#generate_raw_file(raw_file_path, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wave_to_json/audio.rb', line 31 def generate_raw_file(raw_file_path, ={}) command = [ 'sox', @path, '-t', 'raw', '-r', '44100', '-c', '1', '-e', 'signed-integer', '-L', raw_file_path ] if [:channel] == :left command.concat(%w(remix 1 1)) elsif [:channel] == :right command.concat(%w(remix 2 2)) end ShellCommand.new(command).execute end |
#number_of_channels ⇒ Object
15 16 17 18 |
# File 'lib/wave_to_json/audio.rb', line 15 def number_of_channels return @number_of_channels if @number_of_channels @number_of_channels = ShellCommand.new(['soxi', '-c', @path]).run_and_return_output_if_success.to_i end |
#raw_data(options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wave_to_json/audio.rb', line 20 def raw_data( = {}) command = [ 'sox', @path, '-t', 'raw', '-r', '44100', '-c', '1', '-e', 'signed-integer', '-L', '-' ] if [:channel] == :left command.concat(%w(remix 1 1)) elsif [:channel] == :right command.concat(%w(remix 2 2)) end ShellCommand.new(command).run_and_return_output_if_success.unpack('l*') end |