class Cogibara::Transcriber

Public Instance Methods

make_temp_file(file) click to toggle source
# 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) click to toggle source
# File lib/cogibara/transcriber.rb, line 11
def remove_temp_file(filestring)
  `rm ./#{filestring}`
end
transcribe(file) click to toggle source
# 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) click to toggle source
# 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