#!/usr/bin/env python3 import os import struct from datetime import datetime from threading import Thread import numpy as np import pvporcupine import pyaudio import soundfile import speech_recognition as sr recognizer = sr.Recognizer() raw = audio_stream.read(porcupine.frame_length, exception_on_overflow=False) pcm = struct.unpack_from("h" * porcupine.frame_length, raw) result = porcupine.process(pcm) speech = sr.AudioData( frame_data = bytes(raw), sample_rate = porcupine.sample_rate, sample_width = 2, # 16 bits ) command = recognizer.recognize_google(speech) print('[%s] >>>>>>>>>>>>> Google says command was %s' % ( str(datetime.now()), command) )