recognizing_state.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:susi_linux 作者: fossasia 项目源码 文件源码
def on_enter(self, payload=None):
        """ Executed on the entry to the Recognizing State. Upon entry, audio is captured from the Microphone and
        recognition with preferred speech recognition engine is done. If successful, the machine transitions to Busy
        State. On failure, it transitions to Error state.
        :param payload: No payload is expected by this state
        :return: None
        """

        self.notify_renderer('listening')
        recognizer = self.components.recognizer
        try:
            print("Say something!")
            with self.components.microphone as source:
                audio = recognizer.listen(source, phrase_time_limit=5)
            self.notify_renderer('recognizing')
            print("Got it! Now to recognize it...")
            try:
                value = self.__recognize_audio(
                    audio=audio, recognizer=recognizer)
                print(value)
                self.notify_renderer('recognized', value)
                self.transition(self.allowedStateTransitions.get(
                    'busy'), payload=value)
            except sr.UnknownValueError:
                print("Oops! Didn't catch that")
                self.transition(self.allowedStateTransitions.get(
                    'error'), payload='RecognitionError')

            except sr.RequestError as e:
                print(
                    "Uh oh! Couldn't request results from Speech Recognition service; {0}".format(e))
                self.transition(self.allowedStateTransitions.get(
                    'error'), payload='ConnectionError')

        except KeyboardInterrupt:
            pass
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号