Ejemplo n.º 1
0
def dispense_coffee(coffee):
    print "Waiting for Coffee Machine..."
    rospy.wait_for_service('coffee_machine')
    coffee_machine_service = rospy.ServiceProxy('coffee_machine', coffee_machine_control.srv.coffee_machine)
    try:
        for Type in ["caramel", "chocolate", "vanilla", "christmas"]:
            if Type in coffee.lower():
                googleTTS("We're making your coffee now. Please wait")
                print "Requesting a " + Type
                resp = coffee_machine_service(Type)
                print resp
                time.sleep(20)
                return "Your coffee's ready, please take the cup.  Careful, it'll be hot"
        return "That hasn't worked, sorry"
    except rospy.ServiceException, e:
        print "Service call failed: %s"%e
        return "I'm sorry, something's gone wrong.  Please tell the Barista Bot team"
Ejemplo n.º 2
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 sayCallback(data):
    googleTTS(data.data)
Ejemplo n.º 5
0
def messageResponse(witResult, userId, stream):
    baristaDB.OpenDatabase(DatabaseName)
    baristaDB.SetTime(userId)
    print "Got UserId " + str(userId) 
    level = baristaDB.GetInteractionLevel(userId)
    interaction_status['user_id'] = userId
    interaction_status['level'] = level

    finished = False
    try:

#************************************** LEVEL 0  ****************************************

        if (level == 0):

            if (witResult["intent"] == "hello"):
                UID_client.definePerson(userId)
                response = "Hello would you like a coffee?"
                confirm = confirmation(response, stream)
                if confirm:
                    googleTTS("Which coffee would you like, we have Caramel, Vanilla, Christmas and chocolate coffees?")
                    response = "Which type would you like?"
                else:
                    finished = True
                    response = "Unfortunately I can only offer you coffee, I hope you have a nice day - Good Bye"
            
            elif (witResult["intent"] == "coffee_question"):
                UID_client.definePerson(userId)
                googleTTS("Which coffee would you like, we have Caramel, Vanilla, Christmas and chocolate coffees?")
                response = "Which type would you like?"

            elif(witResult["intent"] == "request"):
                UID_client.definePerson(userId)
                if "Coffee" in witResult["entities"]:
                    if(validCoffeeChoice(witResult["entities"]["Coffee"]["value"])):
                        if not "coffee" in witResult["entities"]["Coffee"]["value"]:
                            coffee_choice = witResult["entities"]["Coffee"]["value"] + " Coffee" 
                        else:
                            coffee_choice = witResult["entities"]["Coffee"]["value"]
                        response = baristaDB.GetUserName(userId) + " You have ordered a " + coffee_choice + "."
                        googleTTS(response)
                        coffee_request = witResult["entities"]["Coffee"]["value"]
                        baristaDB.SetCoffeePreference(userId, coffee_request)
                        response = dispense_coffee(coffee_request)
                    else:
                        response = "Which coffee would you like, we have Caramel, Vanilla, Christmas and Chocolate coffees"
                
            elif (witResult["intent"] == "finished"):
                finished = True
                response = "That's great.  Goodbye"
            else:
                response = "I'm sorry, could you repeat that?"
                UID_client.definePerson(userId)

#************************************** LEVEL 1  ****************************************


        elif (level == 1):
            
            if (witResult["intent"] == "hello"):
                response = "Hi, I'm Barista Bot.  What's your name?" 
            elif (witResult["intent"] == "name"):   
                UID_client.definePerson(userId)     
                if "contact" in witResult["entities"]:
                    user_name = witResult["entities"]["contact"]["value"]
                    response = "It's nice to meet you, " + user_name + ". would you like a coffee?"
                    baristaDB.SetUserName(userId, user_name)
                    interaction_status['user_name'] = user_name
                    confirm = confirmation(response, stream)
                    if confirm:
                        response = "Today " + baristaDB.GetUserName(userId) + ", we have Caramel Latte, Vanilla Latte, Christmas Coffee and chocolate"
                    else:
                        finished = True
                        response = "That's okay.  Have a great day! " + baristaDB.GetUserName(userId) + ". Good Bye"
                else:
                    response = "I'm sorry, I didn't catch your name"

            elif (witResult["intent"] == "coffee_question"):
                UID_client.definePerson(userId)
                response = "Oh hello there! What is your name?" 

            elif (witResult["intent"] == "request"):
                UID_client.definePerson(userId)
                if "Coffee" in witResult["entities"]:
                    if(validCoffeeChoice(witResult["entities"]["Coffee"]["value"])):
                        if not "coffee" in witResult["entities"]["Coffee"]["value"]:
                            coffee_choice = witResult["entities"]["Coffee"]["value"] + " Coffee" 
                        else:
                            coffee_choice = witResult["entities"]["Coffee"]["value"]
                        response = baristaDB.GetUserName(userId) + " You have ordered a " + coffee_choice + "."
                        googleTTS(response)
                        coffee_request = witResult["entities"]["Coffee"]["value"]
                        baristaDB.SetCoffeePreference(userId, coffee_request)
                        response = dispense_coffee(coffee_request)
                    else:
                        response = baristaDB.GetUserName(userId) + ", we have Caramel, Vanilla, Christmas and chocolate coffees, which would you like?"
                else:
                    response = "Sorry we only offer Caramel Latte, Vanilla Latte, Christmas Coffee and Chocolate. Would you like a coffee?"
                
            elif (witResult["intent"] == "finished"):
                finished = True
                response = "That's great. Goodbye " + baristaDB.GetUserName(userId)
            else:
                response = "I'm sorry, could you repeat that?"
                UID_client.definePerson(userId)

#************************************** LEVEL 2  ****************************************

#Need to add weather
        elif (level == 2):

            if (witResult["intent"] == "hello"):
                response = "Hi, I'm Barista Bot.  What's your name?" 
            elif (witResult["intent"] == "name"):       
                UID_client.definePerson(userId) 
                if "contact" in witResult["entities"]:
                    user_name = witResult["entities"]["contact"]["value"]
                    response = "It's nice to meet you, " + user_name + ". How are you today?"
                    baristaDB.SetUserName(userId, user_name)
                    interaction_status['user_name'] = user_name
                else:
                    response = "I'm sorry, I didn't catch your name"
                
            elif (witResult["intent"] == "coffee_question"):
                UID_client.definePerson(userId)
                response = "Oh hello there! What is your name?" 

            elif(witResult["intent"] == "emotion"):
                UID_client.definePerson(userId)
                if "Negative_Emotion" in witResult["entities"]:
                    response = "That's a shame, would you like a coffee to make you feel better " + baristaDB.GetUserName(userId)
                    confirm = confirmation(response, stream)
                    if confirm:
                        response = baristaDB.GetUserName(userId) + " we have Caramel, Vanilla, Christmas and chocolate coffees, which would you like?"
                    else:
                        finished = True
                        response = "That's okay.  Have a great day! " + baristaDB.GetUserName(userId) + ". Good Bye"

                elif "Positive_Emotion" in witResult["entities"]:
                    UID_client.definePerson(userId)
                    response = "That's great, would a coffee make you feel even better?" + baristaDB.GetUserName(userId)
                    confirm = confirmation(response, stream)
                    if confirm:
                        response = "Today " + baristaDB.GetUserName(userId) + ", we have Caramel, Vanilla, Christmas and chocolate coffees, which would you like?"
                    else:
                        finished = True
                        response = "That's okay.  Have a great day! " + baristaDB.GetUserName(userId) + ". Good Bye"
            
            elif(witResult["intent"] == "feeling_question"):
                if "Self" in witResult["entities"]:
                    response = "I'm pretty good thanks - Brewing Coffee makes me happy! Can I get you a coffee?"
                    confirm = confirmation(response, stream)
                    if confirm:
                        response = "Today " + baristaDB.GetUserName(userId) + ", we have Caramel, Vanilla, Christmas and chocolate coffees, which would you like?"
                    else:
                        finished = True
                        response = "That's okay.  Have a great day! " + baristaDB.GetUserName(userId) + ". Good Bye"
            

            elif (witResult["intent"] == "request"):
                UID_client.definePerson(userId)
                if "Coffee" in witResult["entities"]:
                    if(validCoffeeChoice(witResult["entities"]["Coffee"]["value"])):
                        if not "coffee" in witResult["entities"]["Coffee"]["value"]:
                            coffee_choice = witResult["entities"]["Coffee"]["value"] + " Coffee" 
                        else:
                            coffee_choice = witResult["entities"]["Coffee"]["value"]
                        response = baristaDB.GetUserName(userId) + " You have ordered a " + coffee_choice + "."
                        googleTTS(response)
                        coffee_request = witResult["entities"]["Coffee"]["value"]
                        baristaDB.SetCoffeePreference(userId, coffee_request)
                        response = dispense_coffee(coffee_request)
                    else:
                        response = baristaDB.GetUserName(userId) + ", we have Caramel, Vanilla, Christmas and chocolate coffees, which would you like?"
                else:
                    response = "Sorry we only offer Caramel Latte, Vanilla Latte, Christmas Coffee and chocolate. Would you like a coffee?"
                
            elif (witResult["intent"] == "finished"):
                finished = True
                response = "That's great. Goodbye " + baristaDB.GetUserName(userId)
            else:
            
                response = "I'm sorry, could you repeat that?"
                UID_client.definePerson(userId)

#************************************** LEVEL 3  ****************************************
        elif(level == 3):

            if (witResult["intent"] == "hello"):
                UID_client.definePerson(userId)
                if baristaDB.UserExists(userId) and baristaDB.GetUserName(userId) != "":
                    response = "Hello there, nice to see you again " + baristaDB.GetUserName(userId) + ". How are you today?"                   
                else:   
                    response = "Hello there, it's a pleasure to meet you, what's your name?"
            elif (witResult["intent"] == "name"):
                UID_client.definePerson(userId)
                if "contact" in witResult["entities"]:
                    user_name = witResult["entities"]["contact"]["value"]
                    response = "It's nice to meet you, " + user_name + ". How are you?"
                    baristaDB.SetUserName(userId, user_name)              
                    interaction_status['user_name'] = user_name
                else:
                    response = "I'm sorry, I didn't catch your name"
            
            elif (witResult["intent"] == "coffee_question"):
                UID_client.definePerson(userId)
                if baristaDB.UserExists(userId) and baristaDB.GetUserName(userId) != "":
                    response = "Hello there, nice to see you again " + baristaDB.GetUserName(userId) + ". How are you today?"                   
                else:   
                    response = "Hello there, it's a pleasure to meet you, what's your name?"    
        

            #THIS EMOTION IS FOR COURSE Feeling.
            elif(witResult["intent"] == "emotion"):
                UID_client.definePerson(userId)
                if "Negative_Emotion" in witResult["entities"]:
                    response = "That's unfortunate, would you like a coffee to improve your day? " + baristaDB.GetUserName(userId)
                    confirm = confirmation(response, stream)
                    if confirm:
                        if baristaDB.GetCoffeePreference(userId) != "":
                            response = "So," + baristaDB.GetUserName(userId) + ", would you like another" + baristaDB.GetCoffeePreference(userId) +"?"
                            confirm = confirmation(response, stream)    
                            if confirm:
                                coffee_request = witResult["entities"]["Coffee"]["value"]
                                baristaDB.SetCoffeePreference(userId, coffee_request)
                                response = dispense_coffee(coffee_request)
                            else:
                                response = baristaDB.GetUserName(userId) + ", we have Caramel, Vanilla, Christmas and chocolate coffees, which would you like?"  
                        else:   
                            response = "Today " + baristaDB.GetUserName(userId) + ", we have Caramel, Vanilla, Christmas and chocolate coffees, which would you like?"
                    else:
                        finished = True
                        response = "That's okay.  Have a great day! " + baristaDB.GetUserName(userId) + ". Good Bye"

                elif "Positive_Emotion" in witResult["entities"]:
                    UID_client.definePerson(userId)
                    response = "That's great, would you like a coffee to improve your productivity?" + baristaDB.GetUserName(userId)
                    confirm = confirmation(response, stream)
                    if confirm:
                        if baristaDB.GetCoffeePreference(userId) != "":
                            response = "So," + baristaDB.GetUserName(userId) + ", would you like another" + baristaDB.GetCoffeePreference(userId) +"?"
                            confirm = confirmation(response, stream)    
                            if confirm:
                                coffee_request = witResult["entities"]["Coffee"]["value"]
                                baristaDB.SetCoffeePreference(userId, coffee_request)
                                response = dispense_coffee(coffee_request)
                            else:
                                response = baristaDB.GetUserName(userId) + ", we have Caramel, Vanilla, Christmas and chocolate coffees, which would you like?"  
                        else:   
                            response = "Today " + baristaDB.GetUserName(userId) + ", we have Caramel, Vanilla, Christmas and chocolate coffees, which would you like?"
                    else:                       
                        finished = True
                        response = "That's okay.  Have a great day! " + baristaDB.GetUserName(userId) + ". Good Bye"
            
            elif(witResult["intent"] == "feeling_question"):
                UID_client.definePerson(userId)
                if "Self" in witResult["entities"]:
                    response = "I'm pretty good thanks - Brewing Coffee makes me happy! Can I get you a coffee?"
                    confirm = confirmation(response, stream)
                    if confirm:
                        response = "Today " + baristaDB.GetUserName(userId) + ", we have Caramel, Vanilla, Christmas and chocolate coffees, which would you like?"
                    else:
                        finished = True
                        response = "That's okay.  Have a great day! " + baristaDB.GetUserName(userId) + ". Good Bye"            

            elif (witResult["intent"] == "request"):
                UID_client.definePerson(userId)
                if "Coffee" in witResult["entities"]:
                    if(validCoffeeChoice(witResult["entities"]["Coffee"]["value"])):
                        if not "coffee" in witResult["entities"]["Coffee"]["value"]:
                            coffee_choice = witResult["entities"]["Coffee"]["value"] + " Coffee" 
                        else:
                            coffee_choice = witResult["entities"]["Coffee"]["value"]
                        response = baristaDB.GetUserName(userId) + " You have ordered a " + coffee_choice + "."
                        googleTTS(response)
                        coffee_request = witResult["entities"]["Coffee"]["value"]
                        baristaDB.SetCoffeePreference(userId, coffee_request)
                        response = dispense_coffee(coffee_request)
                        
                else:
                    response = "Sorry we only offer Caramel Latte, Vanilla Latte, Christmas Coffee and chocolate. Which would you like?"
                
            elif (witResult["intent"] == "finished"):
                finished = True
                response = "That's great. Goodbye " + baristaDB.GetUserName(userId)
            else:
                response = "I'm sorry, could you repeat that?"

#************************************ ALL LEVELS **************************************

        if (witResult["intent"] == "good_bye"):
                finished = True
                response = "Bye!"
        
    except TypeError:
        response = "I'm sorry, I didn't quite get that"
    except SyntaxError:
        response = "Could you repeat that please?"
    
    baristaDB.CloseDatabase(DatabaseName)
    if 'response' in locals():
        return (response, finished)
    else:
        return ("", finished)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
def sayCallback(data):
    googleTTS(data.data)