URI: 
       Add gzip support for raw audio files, import the media generator - warvox - VoIP based wardialing tool, forked from rapid7/warvox.
   DIR Log
   DIR Files
   DIR Refs
   DIR README
       ---
   DIR commit a64de8bc7baea28846729624cb83ec8d32b6d46c
   DIR parent 3a47479fdb9dc463945b69e36fe5a1a71a3f4bc8
  HTML Author: HD Moore <hd_moore@rapid7.com>
       Date:   Sun, 15 Feb 2009 03:47:45 +0000
       
       Add gzip support for raw audio files, import the media generator
       
       
       Diffstat:
         M bin/create_flowdb.rb                |       6 +++---
         A bin/create_media.rb                 |      84 +++++++++++++++++++++++++++++++
         M lib/warvox/audio/raw.rb             |       7 +++++++
       
       3 files changed, 94 insertions(+), 3 deletions(-)
       ---
   DIR diff --git a/bin/create_flowdb.rb b/bin/create_flowdb.rb
       @@ -26,12 +26,12 @@ db  = File.new(dst, "w")
        dir = Dir.new(src)
        cnt = 0
        
       -set = dir.entries.sort.grep(/\.raw$/)
       +set = dir.entries.sort.grep(/\.raw/)
        set.each do |ent|
       -        next if not ent =~ /\.raw$/
       +        next if not ent =~ /\.raw/
                puts "[*] [#{sprintf("%.5d/%.5d", cnt+1, set.length)}] Processing #{ent}..."
                raw = WarVOX::Audio::Raw.from_file( File.join(src, ent) )
       -        db.write( ent.gsub('.raw', '') + " " + raw.to_flow + "\n" )
       +        db.write( ent.gsub(/\.raw|\.gz/, '') + " " + raw.to_flow + "\n" )
                cnt += 1
        end
        
   DIR diff --git a/bin/create_media.rb b/bin/create_media.rb
       @@ -0,0 +1,84 @@
       +#!/usr/bin/env ruby
       +###################
       +
       +#
       +# Load the library path
       +# 
       +base = __FILE__
       +while File.symlink?(base)
       +        base = File.expand_path(File.readlink(base), File.dirname(base))
       +end
       +$:.unshift(File.join(File.expand_path(File.dirname(base)), '..', 'lib'))
       +require 'warvox'
       +
       +#
       +# Script
       +#
       +
       +def usage
       +        $stderr.puts "#{$0} [/path/to/raw/data/] <destination dir> "
       +        exit
       +end
       +
       +require "fileutils"
       +require "tempfile"
       +
       +src = ARGV.shift || usage
       +dst = ARGV.shift || File.join(File.dirname(base), '..', 'data', 'media')
       +
       +FileUtils.mkdir_p(dst)
       +
       +calls = []
       +dir = Dir.new(src)
       +dir.entries.sort.each do |ent|
       +
       +        path = File.join(src, ent)
       +        next if ent !~ /(.*)\.raw/m
       +        num = $1
       +
       +        puts "Processing #{num}..."
       +
       +        # Decompress the audio file
       +        rawfile = Tempfile.new("rawfile")
       +        datfile = Tempfile.new("datfile")
       +
       +        cnt = 0
       +        raw = WarVOX::Audio::Raw.from_file(path)
       +        rawfile.write(raw.samples.pack('v*'))
       +        datfile.write(raw.samples.map{|val| cnt +=1; "#{cnt} #{val}"}.join("\n"))
       +        rawfile.flush
       +        datfile.flush
       +
       +        # Plot samples to a graph
       +        plotter = Tempfile.new("gnuplot")
       +        
       +        plotter.puts("set ylabel \"Signal\"")
       +        plotter.puts("set xlabel \"Time\"")
       +        
       +        plotter.puts("set terminal png medium size 640,480 transparent")
       +        plotter.puts("set output \"#{dst}/#{num}_big.png\"")
       +        plotter.puts("plot \"#{datfile.path}\" using 1:2 title \"#{num}\" with lines")
       +
       +        plotter.puts("set output \"#{dst}/#{num}_big_dots.png\"")
       +        plotter.puts("plot \"#{datfile.path}\" using 1:2 title \"#{num}\" with dots")
       +                        
       +        plotter.puts("set terminal png small size 160,120 transparent")
       +        plotter.puts("set format x ''")
       +        plotter.puts("set format y ''")        
       +        plotter.puts("set output \"#{dst}/#{num}.png\"")
       +        plotter.puts("plot \"#{datfile.path}\" using 1:2 title \"#{num}\" with lines")
       +        plotter.flush
       +        
       +        system("gnuplot #{plotter.path}")
       +        File.unlink(plotter.path)
       +        File.unlink(datfile.path)
       +        plotter.close
       +        datfile.close
       +                
       +        # Generate a MP3 audio file
       +        system("sox -s -w -r 8000 -t raw -c 1 #{rawfile.path} #{dst}/#{num}.wav")
       +        system("lame #{dst}/#{num}.wav #{dst}/#{num}.mp3 >/dev/null 2>&1")
       +        File.unlink("#{dst}/#{num}.wav")
       +        File.unlink(rawfile.path)
       +        rawfile.close
       +end
   DIR diff --git a/lib/warvox/audio/raw.rb b/lib/warvox/audio/raw.rb
       @@ -1,6 +1,9 @@
        module WarVOX
        module Audio
        class Raw
       +        
       +        
       +        require 'zlib'
        
                ##
                # RAW AUDIO - 8khz little-endian 16-bit signed
       @@ -26,6 +29,10 @@ class Raw
                        if(not File.readable?(path))
                                raise Error, "The specified audio file does not exist"
                        end
       +                
       +                if(path =~ /\.gz$/)
       +                        return self.new(Zlib::GzipReader.open(path).read)
       +                end
                
                        self.new(File.read(path, File.size(path)))
                end