xrecognize.py 文件源码

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

项目:CodeLabs 作者: TheIoTLearningInitiative 项目源码 文件源码
def recognize(self):
        if self.engine == 'google':
            try:
                from pprint import pprint
                print("Google Speech Recognition")
                return self.r.recognize_google(self.audio, show_all=False)
            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))
        if self.engine == 'witai':
            WIT_AI_KEY = "7LUFYD6ZZKLYSI652C75J4UZWTIMJIPX"
            try:
                print("Wit.ai")
                return self.r.recognize_wit(self.audio, key=WIT_AI_KEY)
            except sr.UnknownValueError:
                print("Wit.ai could not understand audio")
            except sr.RequestError as e:
                print("Could not request results from Wit.ai service; {0}".format(e))
        if self.engine == 'sphinx':
            try:
                print("Sphinx")
                return self.r.recognize_sphinx(self.audio)
            except sr.UnknownValueError:
                print("Sphinx could not understand audio")
            except sr.RequestError as e:
                print("Sphinx error; {0}".format(e))
        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号