5 from datetime import datetime
6 from threading import Thread
12 import speech_recognition as sr
14 recognizer = sr.Recognizer()
15 raw = audio_stream.read(porcupine.frame_length, exception_on_overflow=False)
16 pcm = struct.unpack_from("h" * porcupine.frame_length, raw)
17 result = porcupine.process(pcm)
19 speech = sr.AudioData(
20 frame_data = bytes(raw),
21 sample_rate = porcupine.sample_rate,
22 sample_width = 2, # 16 bits
24 command = recognizer.recognize_google(speech)
25 print('[%s] >>>>>>>>>>>>> Google says command was %s' % (
26 str(datetime.now()), command)