Use wav as the default output format (more useful) - warvox - Unnamed repositor… | |
Log | |
Files | |
Refs | |
README | |
--- | |
commit 4c244fd8aa041043c0cace51ccddf09dd7ef89bc | |
parent a9ad034c2ca9d3696f4df97850acb722b6570475 | |
Author: HD Moore <[email protected]> | |
Date: Sun, 1 May 2016 23:49:11 -0500 | |
Use wav as the default output format (more useful) | |
Diffstat: | |
M bin/audio_trim.rb | 16 +++++++++------- | |
M bin/export_audio.rb | 10 ++++++++-- | |
2 files changed, 17 insertions(+), 9 deletions(-) | |
--- | |
diff --git a/bin/audio_trim.rb b/bin/audio_trim.rb | |
@@ -3,7 +3,7 @@ | |
# | |
# Load the library path | |
-# | |
+# | |
base = __FILE__ | |
while File.symlink?(base) | |
base = File.expand_path(File.readlink(base), File.dirname(base)) | |
@@ -17,11 +17,13 @@ def usage | |
exit | |
end | |
+# TODO: Needs WAV header support | |
+ | |
# | |
# Script | |
# | |
-off = ARGV.shift | |
+off = ARGV.shift | |
len = ARGV.shift | |
inp = ARGV.shift | |
out = ARGV.shift | |
@@ -33,18 +35,18 @@ end | |
buf = '' | |
ifd = nil | |
-if inp | |
+if inp | |
ifd = ::File.open(inp, "rb") | |
-else | |
+else | |
$stdin.binmode | |
ifd = $stdin | |
end | |
ofd = nil | |
-if out | |
+if out | |
ofd = ::File.open(out, "wb") | |
-else | |
+else | |
$stdout.binmode | |
ofd = $stdout | |
end | |
@@ -52,7 +54,7 @@ end | |
buf = ifd.read | |
off = off.to_i * 16000 | |
-len = (len.to_i > 0) ? len.to_i : (buf.length / 16000).to_i | |
+len = (len.to_i > 0) ? len.to_i : (buf.length / 16000).to_i | |
ofd.write( buf[off, len * 16000] ) | |
exit(0) | |
diff --git a/bin/export_audio.rb b/bin/export_audio.rb | |
@@ -58,8 +58,14 @@ begin | |
m = r.media | |
if m and m.audio | |
- ::File.open(File.join(output, "#{r.number}.raw"), "wb") do |fd| | |
- fd.write(m.audio) | |
+ ::File.open(File.join(output, "#{r.number}.wav"), "wb") do |fd| | |
+ if m.audio[0,4].to_s == "RIFF" | |
+ fd.write(m.audio) | |
+ else | |
+ # Add a WAV header to the sample | |
+ raw = WarVOX::Audio::Raw.new(m.audio) | |
+ fd.write(raw.to_wav) | |
+ end | |
end | |
::File.open(File.join(output, "#{r.number}.yml"), "wb") do |fd| |