Skip to content

Commit

Permalink
add a finishing test
Browse files Browse the repository at this point in the history
  • Loading branch information
taf2 committed Mar 25, 2011
1 parent a3be137 commit 2994034
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/speech/audio_to_text.rb
Expand Up @@ -21,6 +21,10 @@ def to_text
JSON.parse(File.read(self.captured_file))
end

def clean
File.unlink self.captured_file if self.captured_file && File.exist?(self.captured_file)
end

protected

def convert_chunk(easy, chunk, options={})
Expand Down
20 changes: 20 additions & 0 deletions test/audio_to_text_test.rb
@@ -0,0 +1,20 @@
require 'test/unit'
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'speech'

class SpeechAudioToTextTest < Test::Unit::TestCase
def test_audio_to_text
audio = Speech::AudioToText.new("i-like-pickles.wav")
captured_json = audio.to_text
assert captured_json
assert captured_json.key?("captured_json")
assert !captured_json['captured_json'].empty?
assert_equal ['captured_json', 'confidence'], captured_json.keys.sort
assert_equal "I like pickles", captured_json['captured_json'].flatten.first
assert captured_json['confidence'] > 0.9
# {"captured_json"=>[["I like pickles", 0.92731786]], "confidence"=>0.92731786}
# puts captured_json.inspect
ensure
audio.clean
end
end

0 comments on commit 2994034

Please sign in to comment.