Support 8k 16-bit LE wav samples as if they were raw - warvox - VoIP based wardialing tool, forked from rapid7/warvox.
DIR Log
DIR Files
DIR Refs
DIR README
---
DIR commit a9ad034c2ca9d3696f4df97850acb722b6570475
DIR parent 64de9b38015105cdf440fcb6c5bba5e660b8f66d
HTML Author: HD Moore <x@hdm.io>
Date: Sun, 1 May 2016 23:39:14 -0500
Support 8k 16-bit LE wav samples as if they were raw
Diffstat:
M bin/import_audio.rb | 9 +--------
M lib/warvox/audio/raw.rb | 8 ++++++++
2 files changed, 9 insertions(+), 8 deletions(-)
---
DIR diff --git a/bin/import_audio.rb b/bin/import_audio.rb
@@ -38,7 +38,7 @@ require 'config/environment'
project_id = ARGV.shift
provider_id = ARGV.shift
-todo = Dir["#{dir}/**/*.raw"].to_a + Dir["#{dir}/**/*.wav"].to_a
+todo = Dir["#{dir}/**/*.{raw,wav}"].to_a
if todo.empty?
$stderr.puts "Error: No raw audio files found within #{dir}"
@@ -115,13 +115,6 @@ todo.each do |rfile|
mr = dr.media
::File.open(rfile, "rb") do |fd|
-
- # Dirty support for RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
- if rfile =~ /\.wav$/
- # Toss the WAV header
- head = fd.read(44)
- end
-
mr.audio = fd.read(fd.stat.size)
mr.save
end
DIR diff --git a/lib/warvox/audio/raw.rb b/lib/warvox/audio/raw.rb
@@ -52,6 +52,14 @@ class Raw
attr_accessor :samples
def initialize(data)
+
+ # Accept raw WAV files, but remove the header
+ if data[ 0,4].to_s == "RIFF" &&
+ data[ 8,4].to_s == "WAVE" &&
+ data[36,4].to_s == "data"
+ data[0, 44] = ''
+ end
+
self.samples = data.unpack('v*').map do |s|
(s > 0x7fff) ? (0x10000 - s) * -1 : s
end