├── README.md └── ChatGPT-Cozmo.py /README.md: -------------------------------------------------------------------------------- 1 | DISCONTINUED UNTIL FURTHER NOTICE. -------------------------------------------------------------------------------- /ChatGPT-Cozmo.py: -------------------------------------------------------------------------------- 1 | while True: 2 | from pyChatGPT import ChatGPT 3 | import speech_recognition as sr 4 | import cozmo 5 | import time 6 | import random 7 | 8 | 9 | # replace with chatgpt secret key. You will get this in insepct-->applications-->cockies 10 | session_token = '' 11 | api = ChatGPT(session_token, conversation_id='e12185d9-7e59-48a8-9c0d-bbba3c210297') 12 | 13 | 14 | def chat(): 15 | r = sr.Recognizer() 16 | 17 | with sr.Microphone() as source: 18 | audio = r.listen(source) 19 | 20 | try: 21 | query = r.recognize_google(audio) 22 | print("You said: " + query) 23 | except sr.UnknownValueError: 24 | print("Google Speech Recognition could not understand audio") 25 | except sr.RequestError as e: 26 | print("Could not request results from Google Speech Recognition service; {0}".format(e)) 27 | 28 | print("query: ", query) 29 | 30 | response = api.send_message(str(query)) 31 | message1 = response["message"] 32 | print(response["message"]) 33 | return message1 34 | 35 | returned_message = chat() 36 | 37 | 38 | def cozmo_program(robot: cozmo.robot.Robot): 39 | robot.say_text(returned_message).wait_for_completed() 40 | 41 | if "Happy'" in returned_message: 42 | print("ran") 43 | robot.play_anim_trigger(cozmo.anim.Triggers.CodeLabWin).wait_for_completed() 44 | 45 | if "Dance'" in returned_message: 46 | print("ran") 47 | robot.play_anim_trigger(cozmo.anim.Triggers.CodeLabDancingMambo).wait_for_completed() 48 | 49 | if "Sad'" in returned_message: 50 | print("ran") 51 | robot.play_anim_trigger(cozmo.anim.Triggers.CodeLabLose).wait_for_completed() 52 | 53 | 54 | 55 | cozmo.run_program(cozmo_program) 56 | --------------------------------------------------------------------------------