Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove larger chunks and sort as revisions

  • Loading branch information...
commit 64fea0aca3d9b68f4ce32a9a500c19a1dd02360e 1 parent a646880
@taf2 authored
Showing with 264 additions and 15 deletions.
  1. +155 −0 revision.rb
  2. +9 −6 splitter.c
  3. +100 −9 wav2txt
View
155 revision.rb
@@ -0,0 +1,155 @@
+#!/usr/bin/env ruby
+# see: http://chillibear.org/2010/04/comparing-version-numbers-with-ruby.html
+# Revision class
+# Designed to function in version comparisons, where the
+# version number matches /\d+(\.\d+)*/
+
+# Author: Hugh Sasse, De Montfort University <hgs@dmu.ac.uk>
+
+# Created: 06-OCT-2000
+# Last Modified: 13-APR-2010
+
+class Revision
+
+ attr :contents
+
+ def to_i
+ @contents.collect { |j| j.to_i }
+ end
+
+ def to_s
+ astring = @contents.collect { |j| j.to_s }
+ astring.join(".")
+ end
+
+ def <=>(x)
+ @contents <=> x.contents
+ end
+
+ def <(x)
+ comparison = @contents <=> x.contents
+ case comparison
+ when -1
+ result = true
+ when 0
+ result = false
+ when 1
+ result = false
+ end
+ result
+ end
+
+ def >(x)
+ comparison = @contents <=> x.contents
+ case comparison
+ when -1
+ result = false
+ when 0
+ result = false
+ when 1
+ result = true
+ end
+ result
+ end
+
+ def ==(x)
+ comparison = @contents <=> x.contents
+ case comparison
+ when -1
+ result = false
+ when 0
+ result = true
+ when 1
+ result = false
+ end
+ result
+ end
+
+ def initialize(thing)
+ if thing.class == Revision
+ @contents = thing.contents.dup
+ # dup so we get a new copy, not a pointer to it.
+ elsif thing.class == String
+ result = thing.split(".").collect {|j| j.to_i}
+ @contents = result
+ elsif thing.class == Float
+ @contents = thing.to_s.split(".").collect {|j| j.to_i}
+ else
+ raise "cannot initialise to #{thing}"
+ end
+ end
+
+end
+
+if __FILE__ == $0
+
+ # Perform RubyUnit tests
+
+ require "runit/testcase"
+ require 'runit/cui/testrunner'
+ require 'runit/testsuite'
+
+ class Testing_class < RUNIT::TestCase
+ def test_a
+ a = Revision.new("1.2.3")
+ assert_equal([1,2,3], a.contents, "initialize failed #{a.contents}")
+ a = Revision.new("2.4.8")
+ b = Revision.new(a)
+ assert_equal([2,4,8], b.contents, "initialize failed #{a.contents}")
+ a = Revision.new(2.3)
+ assert_equal([2,3], a.contents, "initialize failed #{a.contents}")
+ end
+ def test_equal
+ a = Revision.new("1.2.1")
+ b = Revision.new("1.2.1")
+ assert(a == b, "supposedly identical Revisions are not.")
+ a = Revision.new("2.2.2")
+ b = Revision.new("2.2.1")
+ assert(!(a == b), "supposedly inidentical Revisions are not.")
+ end
+ def test_less_than
+ a = Revision.new("1.2.1")
+ b = Revision.new("1.2.2")
+ assert(a < b, " 1.2.1 not less that 1.2.2 ")
+ a = Revision.new("1.2.2")
+ b = Revision.new("1.3.2")
+ assert(a < b, " 1.2.2 not less that 1.3.2 ")
+ a = Revision.new("1.2.2")
+ b = Revision.new("2.2.2")
+ assert(a < b, " 1.2.2 not less that 2.2.2 ")
+ a = Revision.new("1.2.3.4")
+ b = Revision.new("1.2.3.5")
+ assert(a < b, " 1.2.3.4 not less that 1.2.3.5 ")
+ a = Revision.new("1.2.3")
+ b = Revision.new("1.2.3.5")
+ assert(a < b, " 1.2.3 not less that 1.2.3.5 ")
+ # check comparison is numeric, not lexical
+ a = Revision.new("1.2.3")
+ b = Revision.new("1.12.3")
+ assert(a < b, " 1.2.3 not less that 1.2.3.5 ")
+ end
+ def test_greater_than
+ a = Revision.new("1.2.2")
+ b = Revision.new("1.2.1")
+ assert(a > b, " 1.2.1 not less that 1.2.2 ")
+ a = Revision.new("1.3.2")
+ b = Revision.new("1.2.2")
+ assert(a > b, " 1.2.2 not less that 1.3.2 ")
+ a = Revision.new("2.2.2")
+ b = Revision.new("1.2.2")
+ assert(a > b, " 1.2.2 not less that 2.2.2 ")
+ a = Revision.new("1.2.3.5")
+ b = Revision.new("1.2.3.4")
+ assert(a > b, " 1.2.3.4 not less that 1.2.3.5 ")
+ a = Revision.new("1.2.3.5")
+ b = Revision.new("1.2.3")
+ assert(a > b, " 1.2.3 not less that 1.2.3.5 ")
+ # check comparison is numeric, not lexical
+ a = Revision.new("1.12.3")
+ b = Revision.new("1.2.3")
+ assert(a > b, " 1.2.3 not less that 1.2.3.5 ")
+ end
+ end
+
+ RUNIT::CUI::TestRunner.run(Testing_class.suite)
+end
View
15 splitter.c
@@ -44,23 +44,23 @@ static SilenceDetector* silence_detector_parse_cli(int argc, char **argv) {
while ((ch = getopt(argc, argv, "b:i:t:d:D:w:")) != -1) {
switch (ch) {
- case 'b':
+ case 'b': // how large of a buffer will impact how many frames we look at for each root means. larger byte buffer more frames are compressed into a single root means square
buffer_size = atoi(optarg);
break;
- case 'i':
+ case 'i': // the input wave audio file to split up by silence break points
input_wav_file = optarg;
break;
- case 't':
+ case 't': // a wave magnitude threshold e.g. anything greater than this value will be considered sound
threshold = atoi(optarg);
break;
case 'd':
- min_duration = atof(optarg);
+ min_duration = atof(optarg); // if a chunk is created and it is shorter than this length in time it will be discarded as noise
break;
case 'D':
- max_duration = atof(optarg);
+ max_duration = atof(optarg); // if a chunk is created and is greater in length than it will be reprocessed using an increased threshold(t) and decreased byte buffer(b).
break;
case 'w':
- output_wave = optarg;
+ output_wave = optarg; // can be nice to see the wave curve useful when trying to understand the audio file... cat out.audiowave | ruby plot.viz.rb && open out.wave.png
break;
case '?':
default:
@@ -286,4 +286,7 @@ static void silence_detector_verify_last_chunk_duration(SilenceDetector *ptr) {
SilenceDetector *nd = silence_detector_new(ptr->last_chunk_file_name, (ptr->buffer_size / 2), (ptr->threshold + 10), ptr->min_duration, ptr->max_duration, NULL);
silence_detector_split_audio(nd);
silence_detector_free(nd);
+ unlink(ptr->last_chunk_file_name);
+ free(ptr->last_chunk_file_name);
+ ptr->last_chunk_file_name = NULL;
}
View
109 wav2txt
@@ -1,6 +1,8 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
+$:.unshift File.expand_path(File.dirname(__FILE__))
+require 'revision'
if ARGV.size == 0
puts "usage #{$0} input.wav"
@@ -9,19 +11,106 @@ end
input = ARGV[0]
-system("./splitter -i #{input} -t 45 -d 0.3")
+system("./splitter -i #{input} -t 15 -d 0.3")
path = File.dirname(input)
results = []
confidence = 0
count = 0
root_name = File.basename(input).gsub(/\.wav$/,'')
+=begin
+[["0"], ["0"]]
+[["0"], ["1"]]
+[["0"], ["2"]]
+[["0"], ["3"]]
+[["0"], ["8"]]
+[["1"], ["1"], ["3"], ["0"], ["1"], ["0"]]
+[["1"], ["1"], ["3"], ["0"], ["1"], ["3"], ["1"]]
+[["1"], ["1"], ["3"], ["0"], ["1"], ["3"], ["7"]]
+[["1"], ["1"], ["3"], ["0"], ["1"], ["3"], ["8"]]
+[["1"], ["1"], ["3"], ["0"], ["1"], ["3"], ["9"]]
+[["1"], ["1"], ["3"], ["0"], ["1"], ["4"]]
+[["1"], ["1"], ["3"], ["0"], ["1"], ["6"]]
+[["1"], ["1"], ["3"], ["0"], ["1"], ["7"]]
+[["1"], ["1"], ["3"], ["0"], ["1"], ["8"]]
+[["1"], ["1"], ["3"], ["0"], ["4"], ["3"]]
+[["1"], ["1"], ["3"], ["0"], ["4"], ["4"]]
+[["1"], ["1"], ["3"], ["0"], ["7"], ["1"], ["5"]]
+[["1"], ["1"], ["3"], ["0"], ["7"], ["6"]]
+[["1"], ["1"], ["3"], ["0"], ["7"], ["7"]]
+[["1"], ["1"], ["3"], ["0"], ["7"], ["8"], ["1"]]
+[["1"], ["1"], ["3"], ["0"], ["7"], ["8"], ["1"], ["7"]]
+[["1"], ["1"], ["3"], ["0"], ["7"], ["8"], ["1"], ["8"]]
+[["1"], ["1"], ["3"], ["0"], ["7"], ["8"], ["2"]]
+[["1"], ["1"], ["3"], ["0"], ["7"], ["8"], ["2"], ["0"]]
+[["1"], ["1"], ["3"], ["0"], ["7"], ["8"], ["3"]]
+[["1"], ["1"], ["3"], ["0"], ["7"], ["8"], ["6"]]
+[["1"], ["1"], ["3"], ["1"], ["1"], ["0"]]
+[["1"], ["1"], ["3"], ["1"], ["1"], ["1"]]
+[["1"], ["1"], ["3"], ["1"], ["1"], ["2"], ["0"]]
+[["1"], ["1"], ["3"], ["1"], ["1"], ["2"], ["1"], ["1"]]
+[["1"], ["1"], ["3"], ["1"], ["1"], ["2"], ["7"]]
+[["1"], ["1"], ["3"], ["1"], ["1"], ["2"], ["8"]]
+[["1"], ["1"], ["3"], ["2"]]
+[["1"], ["1"], ["3"], ["4"], ["1"], ["9"], ["1"]]
+[["1"], ["1"], ["3"], ["4"], ["1"], ["9"], ["2"]]
+[["1"], ["1"], ["3"], ["4"], ["1"], ["9"], ["3"]]
+[["1"], ["1"], ["3"], ["4"], ["2"], ["0"]]
+[["1"], ["1"], ["3"], ["4"], ["2"], ["1"], ["1"]]
+[["1"], ["1"], ["3"], ["4"], ["2"], ["1"], ["2"]]
+[["1"], ["1"], ["3"], ["4"], ["2"], ["1"], ["3"]]
+[["1"], ["1"], ["3"], ["4"], ["2"], ["1"], ["4"]]
+[["1"], ["1"], ["3"], ["4"], ["2"], ["1"], ["5"]]
+[["1"], ["1"], ["3"], ["4"], ["3"]]
+[["1"], ["1"], ["3"], ["4"], ["5"]]
+[["1"], ["1"], ["3"], ["4"], ["8"]]
+[["1"], ["1"], ["4"], ["1"], ["0"]]
+[["1"], ["1"], ["4"], ["1"], ["2"]]
+[["1"], ["1"], ["4"], ["1"], ["3"]]
+[["1"], ["1"], ["4"], ["2"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["0"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["1"], ["0"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["1"], ["3"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["1"], ["4"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["1"], ["5"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["1"], ["9"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["2"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["2"], ["7"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["2"], ["8"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["3"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["3"], ["2"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["3"], ["3"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["3"], ["8"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["4"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["7"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["8"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["0"], ["9"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["3"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["5"]]
+[["1"], ["1"], ["5"], ["1"], ["0"], ["6"]]
+[["1"], ["1"], ["5"], ["1"], ["1"]]
+[["1"], ["1"], ["5"], ["1"], ["4"]]
+[["1"], ["2"]]
+[["2"]]
+[["3"]]
+[["4"]]
+[["8"]]
+[["9"]]
+=end
# it's important that contiguous chunks stay connected otherwise partial words might be sent for transcribing
-chunks = Dir["#{path}/#{root_name}*.wav.chunk*"].sort_by do|wave|
- wave.gsub(/.*\.chunk/,'').to_i
+chunks = Dir["#{path}/#{root_name}*.wav.chunk*"].sort do|a, b|
+ da = a.scan(/(\d+)/)
+ dav = da.flatten.join(".")
+
+ db = b.scan(/(\d+)/)
+ dbv = db.flatten.join(".")
+
+ Revision.new(dav) <=> Revision.new(dbv)
end
+puts chunks.map{|c| puts c }.inspect
+
chunks.each do|wave|
puts wave.inspect
chunk_file = wave.gsub(/\.wav/,'') + ".wav"
@@ -30,9 +119,9 @@ chunks.each do|wave|
wave_text = chunk_file.gsub(/\.wav$/,'.json')
if File.exist?(wave_text)
out = JSON.parse(File.read(wave_text))
- if out && out['captured_json'] && out['captured_json'].first
- results << out['captured_json'].first.first
- confidence += out['confidence']
+ if out && out['hypotheses'] && !out['hypotheses'].empty?
+ results << out['hypotheses'].first.first
+ confidence += out['hypotheses'].first.last
count += 1
end
end
@@ -44,14 +133,16 @@ if chunks.size == 0
wave_text = input.gsub(/\.wav$/,'.json')
if File.exist?(wave_text)
out = JSON.parse(File.read(wave_text))
- if out && out['captured_json'] && out['captured_json'].first
- results << out['captured_json'].first.first
- confidence += out['confidence']
+ if out && out['hypotheses'] && !out['hypotheses'].empty?
+ results << out['hypotheses'].first.first
+ confidence += out['hypotheses'].first.last
count += 1
end
end
end
+puts chunks.inspect
+
confidence /= count
puts results.join(" ")
puts confidence
Please sign in to comment.
Something went wrong with that request. Please try again.