| audio_trim.rb - warvox - VoIP based wardialing tool, forked from rapid7/warvox. | |
| git clone git://jay.scot/warvox | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| audio_trim.rb (876B) | |
| --- | |
| 1 #!/usr/bin/env ruby | |
| 2 ################### | |
| 3 | |
| 4 # | |
| 5 # Load the library path | |
| 6 # | |
| 7 base = __FILE__ | |
| 8 while File.symlink?(base) | |
| 9 base = File.expand_path(File.readlink(base), File.dirname(base)) | |
| 10 end | |
| 11 $:.unshift(File.join(File.expand_path(File.dirname(base)), '..', 'lib')) | |
| 12 | |
| 13 require 'warvox' | |
| 14 | |
| 15 def usage | |
| 16 $stderr.puts "Usage: #{$0} [offset] [length] <input.raw> <output.raw>" | |
| 17 exit | |
| 18 end | |
| 19 | |
| 20 # TODO: Needs WAV header support | |
| 21 | |
| 22 # | |
| 23 # Script | |
| 24 # | |
| 25 | |
| 26 off = ARGV.shift | |
| 27 len = ARGV.shift | |
| 28 inp = ARGV.shift | |
| 29 out = ARGV.shift | |
| 30 | |
| 31 if (off and off == "-h") or not off | |
| 32 usage() | |
| 33 end | |
| 34 | |
| 35 buf = '' | |
| 36 ifd = nil | |
| 37 | |
| 38 if inp | |
| 39 ifd = ::File.open(inp, "rb") | |
| 40 else | |
| 41 $stdin.binmode | |
| 42 ifd = $stdin | |
| 43 end | |
| 44 | |
| 45 ofd = nil | |
| 46 | |
| 47 if out | |
| 48 ofd = ::File.open(out, "wb") | |
| 49 else | |
| 50 $stdout.binmode | |
| 51 ofd = $stdout | |
| 52 end | |
| 53 | |
| 54 | |
| 55 buf = ifd.read | |
| 56 off = off.to_i * 16000 | |
| 57 len = (len.to_i > 0) ? len.to_i : (buf.length / 16000).to_i | |
| 58 | |
| 59 ofd.write( buf[off, len * 16000] ) | |
| 60 exit(0) | |
| 61 | |
| 62 | |
| 63 |