main.py 文件源码

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

项目:Onyx 作者: OnyxProject 项目源码 文件源码
def detected_callback(self):
        self.detector.terminate()
        play_wav(onyx.__path__[0] + "/client/speech/resources/ding.wav")

        r = sr.Recognizer()

        with sr.Microphone() as source:
            print("Say something!")
            audio = r.listen(source, timeout=1, phrase_time_limit=5)

        try:
            result = stt.execute(audio, language=self.lang)
            print("You said: " + result)

            def create_ws():
                def onConnected(event=None):
                    print ("Sending message...")
                    payload = {
                            'utterances': [result]
                    }
                    ws.emit(Message('recognizer_loop:utterance', payload))
                    t.close()
                    #self.detector.start(self.detected_callback)


                ws = WebsocketClient()
                ws.on('connected', onConnected)
                # This will block until the client gets closed
                ws.run_forever()

            t = threading.Thread(target=create_ws)
            t.start()
            time.sleep(2)
            self.detector.start(self.detected_callback)


        except sr.UnknownValueError:
            print("Speech Recognition could not understand audio")
        except sr.RequestError as e:
            print("Could not request results from Speech Recognition service; {0}".format(e))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号