def confirmation(response, stream): witResult = {"intent" : None} while not (witResult["intent"] in ["affirmative", "negative"]): calibrate_input_threshold(stream) googleTTS(response) flac_file = listen_for_block_of_speech(stream) override = server_globals['witResultOverride'] server_globals['witResultOverride'] = None if override: witResult = override server_globals['pub_speech'].publish(str(override)) else: hypothesis = stt_google_wav(flac_file) if hypothesis: server_globals['pub_speech'].publish(hypothesis) witResult = witLookup(hypothesis) if witResult: if (witResult["intent"] == "affirmative"): return True elif (witResult["intent"] == "negative"): return False return False
def begin_interaction(stream): global finished, Paused, userID, witResultOverride flacrecord.calibrate_input_threshold(stream) googleTTS("Greetings! After the tone, please speak clearly towards my face. Don't forget to say Hello!") Paused = False finished = False while not finished and not rospy.is_shutdown(): while (Paused): pass flac_file = listen_for_block_of_speech(stream) if finished: break if not flac_file == []: if finished: break override = witResultOverride witResultOverride = None if override: pub_speech.publish(str(override)) responseString, finished = responseprocess.messageResponse(override, userID, stream) print responseString googleTTS(responseString) else: hypothesis = stt_google_wav(flac_file) if hypothesis: pub_speech.publish(hypothesis) if hypothesis.lower() == "what does the fox say": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/fox.wav')) elif hypothesis.lower() == "do you have a license": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/mate.wav')) elif hypothesis.lower() == "do you work out": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/work.wav')) elif hypothesis.lower() == "something strange in the neighborhood": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/ghost.wav')) elif hypothesis.lower() == "attention": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/attention.wav')) elif hypothesis.lower() == "i'm talking to you": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/talking.wav')) elif hypothesis.lower() == "i don't want you": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/want.wav')) elif hypothesis.lower() == "how did we meet": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/met.wav')) elif hypothesis.lower() == "do you have any popcorn": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/popcorn.wav')) elif hypothesis.lower() == "how did you get to work today": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/underground.wav')) elif hypothesis.lower() == "which man are you": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/tetris.wav')) elif hypothesis.lower() == "what are you": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/blue.wav')) elif hypothesis.lower() == "the dogs are out": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/dogs.wav')) elif hypothesis.lower() == "what did she say": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/love.wav')) elif hypothesis.lower() == "is there a house in new orleans": play_wav(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/orleans.wav')) else : witResult = witLookup(hypothesis) if witResult != []: responseString, finished = responseprocess.messageResponse(witResult, userID, stream) else: responseString = responseprocess.randomNegative() flacrecord.calibrate_input_threshold(stream) googleTTS(responseString) else: responseString = responseprocess.randomNegative() flacrecord.calibrate_input_threshold(stream) googleTTS(responseString) else: responseString = responseprocess.randomNegative() flacrecord.calibrate_input_threshold(stream) googleTTS(responseString)
wf = wave.open(filename + '.wav', 'wb') wf.setnchannels(1) wf.setsampwidth(p.get_sample_size(globalvariables.FORMAT)) wf.setframerate(globalvariables.SAMPLERATE) wf.writeframes(data) wf.close() return filename def convert_wav_to_flac(filename): os.system(FLAC_CONV + filename + '.wav') os.remove(filename + '.wav') flac_filename = filename + '.flac' return flac_filename FLAC_CONV = 'flac -f ' # We need a WAV to FLAC converter. if (__name__ == '__main__'): import googlewebspeech # Unit test when module is run rospy.init_node("flac_record") stream = open_stream() init_faceid_subscription() init_ros_override_services() # calibrate_input_threshold(stream) filename = listen_for_block_of_speech(stream) if filename: os.system('mplayer ' + filename) print googlewebspeech.stt_google_wav(filename) # os.remove(filename)
def begin_interaction(stream): global finished, Paused, userID, witResultOverride flacrecord.calibrate_input_threshold(stream) googleTTS( "Greetings! After the tone, please speak clearly towards my face. Don't forget to say Hello!" ) Paused = False finished = False while not finished and not rospy.is_shutdown(): while (Paused): pass flac_file = listen_for_block_of_speech(stream) if finished: break if not flac_file == []: if finished: break override = witResultOverride witResultOverride = None if override: pub_speech.publish(str(override)) responseString, finished = responseprocess.messageResponse( override, userID, stream) print responseString googleTTS(responseString) else: hypothesis = stt_google_wav(flac_file) if hypothesis: pub_speech.publish(hypothesis) if hypothesis.lower() == "what does the fox say": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/fox.wav')) elif hypothesis.lower() == "do you have a license": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/mate.wav')) elif hypothesis.lower() == "do you work out": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/work.wav')) elif hypothesis.lower( ) == "something strange in the neighborhood": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/ghost.wav')) elif hypothesis.lower() == "attention": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/attention.wav')) elif hypothesis.lower() == "i'm talking to you": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/talking.wav')) elif hypothesis.lower() == "i don't want you": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/want.wav')) elif hypothesis.lower() == "how did we meet": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/met.wav')) elif hypothesis.lower() == "do you have any popcorn": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/popcorn.wav')) elif hypothesis.lower() == "how did you get to work today": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/underground.wav')) elif hypothesis.lower() == "which man are you": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/tetris.wav')) elif hypothesis.lower() == "what are you": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/blue.wav')) elif hypothesis.lower() == "the dogs are out": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/dogs.wav')) elif hypothesis.lower() == "what did she say": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/love.wav')) elif hypothesis.lower( ) == "is there a house in new orleans": play_wav( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'easter_eggs/orleans.wav')) else: witResult = witLookup(hypothesis) if witResult != []: responseString, finished = responseprocess.messageResponse( witResult, userID, stream) else: responseString = responseprocess.randomNegative() flacrecord.calibrate_input_threshold(stream) googleTTS(responseString) else: responseString = responseprocess.randomNegative() flacrecord.calibrate_input_threshold(stream) googleTTS(responseString) else: responseString = responseprocess.randomNegative() flacrecord.calibrate_input_threshold(stream) googleTTS(responseString)
data = ''.join(data) wf = wave.open(filename+'.wav', 'wb') wf.setnchannels(1) wf.setsampwidth(p.get_sample_size(globalvariables.FORMAT)) wf.setframerate(globalvariables.SAMPLERATE) wf.writeframes(data) wf.close() return filename def convert_wav_to_flac(filename): os.system(FLAC_CONV + filename+'.wav') os.remove(filename+'.wav') flac_filename = filename+'.flac' return flac_filename FLAC_CONV = 'flac -f ' # We need a WAV to FLAC converter. if(__name__ == '__main__'): import googlewebspeech # Unit test when module is run rospy.init_node("flac_record") stream = open_stream() init_faceid_subscription() init_ros_override_services() # calibrate_input_threshold(stream) filename = listen_for_block_of_speech(stream) if filename: os.system('mplayer ' + filename) print googlewebspeech.stt_google_wav(filename) # os.remove(filename)