Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyAudio delay
#1
So i'm currently making a voice assistant thingy as a school project and i have quite a problem with pyaudio.
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?
Reply


Messages In This Thread
PyAudio delay - by hast - Jan-23-2018, 09:17 PM
RE: PyAudio delay - by j.crater - Jan-23-2018, 09:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Raspberry PI - PyAudio - Streaming to Web Page ultimatecodewarrior 2 887 Dec-25-2024, 10:54 AM
Last Post: pintailscratchy
  pyaudio seems to randomly halt input. elpidiovaldez5 2 1,372 Jan-22-2024, 09:07 AM
Last Post: elpidiovaldez5
  Is it possible to add a delay right after a request.get() cubangt 6 11,033 Sep-07-2023, 09:29 AM
Last Post: shoesinquiry
  Request Delay pheadrus 1 5,215 Nov-25-2021, 08:51 PM
Last Post: snippsat
  adding a delay on end Daz2264 6 3,794 Sep-29-2021, 02:57 PM
Last Post: deanhystad
  Not getting response from pyaudio OceansBlue 1 3,715 Jul-03-2021, 06:22 AM
Last Post: OceansBlue
  python delay without interrupt the whole code Nick_tkinter 4 7,603 Feb-22-2021, 10:51 PM
Last Post: nilamo
  help with PyAudio Leo12143 1 2,867 Jan-18-2021, 09:56 AM
Last Post: DT2000
  pyAudio playing variable Talking2442 3 4,060 Dec-01-2020, 06:20 PM
Last Post: Talking2442
  configure delay on only one link using python3 HiImAl 3 3,720 Oct-21-2020, 07:51 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020