| Remove sox dependency by handling wav conversion directly - warvox - VoIP based… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit d997b94f7515ada2a46c18eb3247edb9facf51fc | |
| parent 8b9384948db26895e2737f227c906c39d285edc9 | |
| Author: HD Moore <[email protected]> | |
| Date: Sat, 6 Aug 2011 17:03:13 +0000 | |
| Remove sox dependency by handling wav conversion directly | |
| Diffstat: | |
| M bin/verify_install.rb | 14 -------------- | |
| M etc/warvox.conf | 1 - | |
| M lib/warvox/audio/raw.rb | 17 +++++++++++++++++ | |
| M lib/warvox/jobs/analysis.rb | 6 ++++-- | |
| 4 files changed, 21 insertions(+), 17 deletions(-) | |
| --- | |
| diff --git a/bin/verify_install.rb b/bin/verify_install.rb | |
| @@ -49,20 +49,6 @@ rescue ::LoadError | |
| exit | |
| end | |
| -sox_path = WarVOX::Config.tool_path('sox') | |
| -if(not sox_path) | |
| - puts "[*] ERROR: The 'sox' binary could not be found" | |
| - exit | |
| -end | |
| - | |
| -sox_data = `#{sox_path} --help 2>&1` | |
| -if(sox_data !~ /raw/) | |
| - puts "[*] ERROR: The 'sox' binary does not have support for RAW audio" | |
| - exit | |
| -end | |
| -puts "[*] The SOX binary appears to be available with RAW file support" | |
| - | |
| - | |
| if(not WarVOX::Config.tool_path('gnuplot')) | |
| puts "[*] ERROR: The 'gnuplot' binary could not be installed" | |
| exit | |
| diff --git a/etc/warvox.conf b/etc/warvox.conf | |
| @@ -22,7 +22,6 @@ data_path: "%BASE%/data/" | |
| # | |
| tools: | |
| gnuplot: gnuplot | |
| - sox: sox | |
| lame: lame | |
| iaxrecord: "%BASE%/bin/iaxrecord.rb" | |
| dtmf2num: "%BASE%/bin/dtmf2num" | |
| diff --git a/lib/warvox/audio/raw.rb b/lib/warvox/audio/raw.rb | |
| @@ -54,6 +54,23 @@ class Raw | |
| (s > 0x7fff) ? (0x10000 - s) * -1 : s | |
| end | |
| end | |
| + | |
| + def to_raw | |
| + self.samples.pack("v*") | |
| + end | |
| + | |
| + def to_wav | |
| + raw = self.to_raw | |
| + wav = | |
| + "RIFF" + | |
| + [raw.length + 36].pack("V") + | |
| + "WAVE" + | |
| + "fmt " + | |
| + [16, 1, 1, 8000, 16000, 2, 16 ].pack("VvvVVvv"… | |
| + "data" + | |
| + [ raw.length ].pack("V") + | |
| + raw | |
| + end | |
| def to_flow(opts={}) | |
| diff --git a/lib/warvox/jobs/analysis.rb b/lib/warvox/jobs/analysis.rb | |
| @@ -347,8 +347,10 @@ class Analysis < Base | |
| tmp_wav = Tempfile.new("wav") | |
| tmp_mp3 = Tempfile.new("mp3") | |
| - # Generate a MP3 audio file | |
| - system("#{WarVOX::Config.tool_path('sox')} -s -2 -r 8000 -t ra… | |
| + # Generate a WAV file from raw linear PCM | |
| + ::File.open(tmp_wav, "wb") do |fd| | |
| + fd.write(raw.to_wav) | |
| + end | |
| # Default samples at 8k, bump it to 32k to get better quality | |
| system("#{WarVOX::Config.tool_path('lame')} -b 32 #{tmp_wav.pa… |