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))
评论列表
文章目录