def hear(source, r, robot):
audio = r.listen(source)
try:
recognized = r.recognize_google(audio)
print("You said: " + recognized)
if command_activate in recognized or command_activate.lower() in recognized:
print("Action command recognized")
if command_pickup in recognized:
do_blocks(robot)
elif command_dance in recognized:
do_dance()
elif command_lookatme in recognized:
do_lookforface(robot)
elif command_followme in recognized:
do_lookforface(robot)
do_followface(robot)
elif command_takepictureofme in recognized:
do_lookforface(robot)
do_takepicture(robot)
elif command_takepicture in recognized:
do_takepicture(robot)
elif command_say in recognized:
do_say(recognized, robot)
else:
print("Command not recognized")
else:
print("You did not say the magic word " + command_activate)
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
评论列表
文章目录