Jan-23-2018, 09:17 PM
So i'm currently making a voice assistant thingy as a school project and i have quite a problem with pyaudio.
And for a voice assistant that is unacceptable.
I don't know where the problem is exactly, but i'm pretty sure it's not the speech recognition part.
Does anybody have a clue why this is happening?
while True: chunk = 256 # get audio from the microphone r = sr.Recognizer() with sr.Microphone() as source: print("Ready") audio = r.listen(source) try: print("You said " + r.recognize_google(audio)) if r.recognize_google(audio) == "hello": f = wave.open("hal1.wav","rb") p = pyaudio.PyAudio() stream = p.open(format = p.get_format_from_width(f.getsampwidth()), channels = f.getnchannels(), rate = f.getframerate(), output = True) data = f.readframes(chunk) while data: stream.write(data) data = f.readframes(chunk) stream.stop_stream() stream.close() p.terminate() except sr.UnknownValueError: print("Could not understand audio") except sr.RequestError as e: print("Could not request results; {0}".format(e))The problem is in the title, there is a MASSIVE delay before the wav file is actually played. (sometimes it can take up to 20 seconds to get it played back)
And for a voice assistant that is unacceptable.
I don't know where the problem is exactly, but i'm pretty sure it's not the speech recognition part.
Does anybody have a clue why this is happening?