Class: AudioGlue::SoxAdapter

Inherits:
BaseAdapter
  • Object
show all
Defined in:
lib/audio_glue/sox_adapter.rb

Overview

Pretty small adapter based on the ruby-sox library. Handles only local files ( snippet type = :file ).

Instance Method Summary collapse

Instance Method Details

#build(snippet_packet) ⇒ String

Write output to a temporary file, read data from it, and remove it.

Parameters:

  • snippet_packet (AudioGlue::SnippetPacket)

Returns:

  • (String)

    audio data as a binary string.



14
15
16
17
18
19
20
21
22
# File 'lib/audio_glue/sox_adapter.rb', line 14

def build(snippet_packet)
  tmp_file = gen_tmp_filename(snippet_packet.format)
  write(snippet_packet, tmp_file)
  File.binread(tmp_file)
rescue ::Sox::Error => err
  raise(::AudioGlue::BuildError, err.message)
ensure
  FileUtils.rm tmp_file if File.exists?(tmp_file)
end