def listen(recognizer, message='Say Something'):
with speech_recognition.Microphone() as source:
print(message)
audio = recognizer.listen(source)
try:
return recognizer.recognize_google(audio).lower()
except speech_recognition.UnknownValueError:
try:
return recognizer.recognize_sphinx(audio).lower()
except speech_recognition.UnknownValueError:
print("Pandora could not understand audio")
except speech_recognition.RequestError as e:
print("Sphinx error; {0}".format(e))
except speech_recognition.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
评论列表
文章目录