Esempio n. 1
0
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)
def calibrateCallback(in_data):
    flacrecord.calibrate_input_threshold()
    return std_srvs.srv.EmptyResponse()
Esempio n. 4
0
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)
Esempio n. 5
0
def calibrateCallback(in_data):
    flacrecord.calibrate_input_threshold()
    return std_srvs.srv.EmptyResponse()