Class: Cogibara::Transcriber
- Inherits:
-
Object
- Object
- Cogibara::Transcriber
- Defined in:
- lib/cogibara/transcriber.rb
Instance Method Summary collapse
- #make_temp_file(file) ⇒ Object
- #remove_temp_file(filestring) ⇒ Object
- #transcribe(file) ⇒ Object
- #transcribe_lang(file, language) ⇒ Object
Instance Method Details
#make_temp_file(file) ⇒ Object
5 6 7 8 9 |
# File 'lib/cogibara/transcriber.rb', line 5 def make_temp_file(file) fname = "tempfile-"+((Time.now.to_f*100000).to_i.to_s) File.open(fname,'wb') {|f| f.write(file)} fname end |
#remove_temp_file(filestring) ⇒ Object
11 12 13 |
# File 'lib/cogibara/transcriber.rb', line 11 def remove_temp_file(filestring) `rm ./#{filestring}` end |
#transcribe(file) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cogibara/transcriber.rb', line 15 def transcribe(file) filestring = make_temp_file(file) result = Speech::AudioToText.new(filestring).to_json #(2, "en-US") remove_temp_file filestring # puts result if(result["hypotheses"].first) result["hypotheses"].first.first else # "Sorry, I didn't understand that".to_speech Cogibara::say "Sorry, I didn't understand that" nil end end |
#transcribe_lang(file, language) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cogibara/transcriber.rb', line 29 def transcribe_lang(file, language) filestring = make_temp_file(file) result = Speech::AudioToText.new(filestring).to_json(2, language) remove_temp_file filestring # puts result if(result["hypotheses"].first) result["hypotheses"].first.first else # "Sorry, I didn't understand that".to_speech Cogibara::say "Sorry, I didn't understand that" nil end end |