def apiai_callback(self, recognizer, audio):
"""
called from the background thread
:param recognizer:
:param audio:
:return:
"""
try:
captured_audio = recognizer.recognize_api(audio,
client_access_token=self.key,
language=self.language,
session_id=self.session_id,
show_all=self.show_all)
Utils.print_success("Apiai Speech Recognition thinks you said %s" % captured_audio)
self._analyse_audio(captured_audio)
except sr.UnknownValueError as e:
Utils.print_warning("Apiai Speech Recognition could not understand audio; {0}".format(e))
# callback anyway, we need to listen again for a new order
self._analyse_audio(audio_to_text=None)
except sr.RequestError as e:
Utils.print_danger("Could not request results from Apiai Speech Recognition service; {0}".format(e))
# callback anyway, we need to listen again for a new order
self._analyse_audio(audio_to_text=None)
# stop listening for an audio
self.stop_listening()
评论列表
文章目录