persia.py 文件源码

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

项目:Persia 作者: rjcf18 项目源码 文件源码
def initiate_Persia(self):
        """
        Initializes Persia and starts the listening loop
        """

        # starts the recognizer
        r = sr.Recognizer()

        with sr.Microphone() as source:

            while True:
                logger.debug("Awaiting user input.")
                audio = r.listen(source)

                logger.debug("Interpreting user input.")

                # Speech recognition using Google Speech Recognition
                try:
                    result = r.recognize_google(audio)
                    #result = r.recognize_sphinx(audio)

                    self.handle_action(result)

                except sr.UnknownValueError:
                    logger.debug("Could not understand audio")
                    #Persia.speak("I'm sorry, but I couldn't understand what you said.")
                except sr.RequestError as e:
                    logger.warn("Could not request results from Google Speech Recognition service: %s", e)
                except Exception as e:
                    logger.error("Could not process text: %s", e)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号