-
Notifications
You must be signed in to change notification settings - Fork 485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Input overflow #10
Comments
I think you are correct. The Python demo runs slow on an RPi zero. Could you try adding: frames_per_buffer=4096, to pa.open() call in porcupine_demo.py ? Also, could you please provide me few pieces of information to reproduce the issue: 1- What is the sample rate for the microphone? If it is not 16000, are you resampling using an ALSA plug? Thanks! |
I changed frames_per_buffer up and down, but no luck.
|
OK. I haven't worked with dsnoop before. So this could be from my lack of knowledge ... But from what I can see the sample rate for your HW is 48000. Porcupine consumes 16000. So there needs to be resampling happening somewhere. Otherwise, we are feeding 48000 audio into Porcupine. That could be a reason as we are doing 3 times more processing. Thoughts? The other obvious thing we can look at is CPU usage. Can you tell me what is the average CPU usage without running the Python demon and what is it when running it? |
Thanks for your help, A. |
We are using pyaudio 0.2.8 and it does not resample at all. In fact, without an ALSA plugin connecting a mic with a different sampling rate will fail initialization of pyaudio for 16000 recording. Let's do these two things: 1- How did you install pyaudio on your RPi? I am going to try to do that and see if I can reproduce the issue. result = porcupine.process(pcm)do you still get the error? think should help isolate the problem. Since your CPU usage does not go up much this really shouldn't happen .... |
|
OK. This is useful. Porcupine is not the reason for causing the overflow error. The demo right now is simply reading audio in chunks from PyAudio and do nothing with it. Are you using the "--output_path"? If yes maybe remove that so we don't even spend time writing into a file. I would suggest these following steps: Let me know how it goes. |
@tfontoura Could you please pass the "stream_callback" optional argument to the pa.open() at line 90 of porcupine_demo.py and remove the while True loop instead? That would do the operation in non-blocking mode and might solve your issue. You basically need to read "porcupine.frame_length" samples from the buffer and call the porcupine.process, same as the code in the while loop. Hope that resolves your issue. |
I was able to remove the error message/throw error by changing line 104 to PS: @amiranhari I'm not sure what you want me to do, can you please post a small sample code? |
I think whats happening is that the buffer overflow is happening and it is just not throwing exceptions. So we are passing incorrect (chopped) audio to Porcupine. That explains why it does not work well ... |
I agree, @kenarsa . I must solve the pyaudio issue. |
@tfontoura I meant something like the attached diff. |
I applied the diff - the error is gone. However, now how do I send the audio stream to porcupine in order to detect the hotword?? |
Oh, I see. it calls the function _audio_callback now. No overflow error now, but no detection as well. |
The callback function calls the Porcupine library to detect the keyword and is working on my Mac. I would recommend:
|
Ok, thanks. Setting |
Glad that it worked. Please close the issue if it's resolved. |
@tfontoura, I am curious how did you use dsnoop with porcupine hotword detection? Does it work with pyAudio? |
@EgorLakomkin, they do work, it's just a matter of selecting the right input for pyaudio (dsnoop as the input). |
Installing on Raspberry PI Zero W with Raspbian, demo runs for about 1-2 seconds and throws:
Traceback (most recent call last): File "demo/python/porcupine_demo.py", line 204, in <module> input_device_index=args.input_audio_device_index).run() File "demo/python/porcupine_demo.py", line 104, in run pcm = audio_stream.read(porcupine.frame_length) File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 608, in read return pa.read_stream(self._stream, num_frames, exception_on_overflow) IOError: [Errno -9981] Input overflowed
Maybe I have to change the frame size? If so, where do I change parameters?
I tested using
python demo/python/porcupine_demo.py --keyword_file_paths resources/keyword_files/alexa_raspberrypi.ppn --output_path ~/testporcupine.wav
it records the file for 2 seconds and stops. I can hear my voice fine in those 2 sec.
The text was updated successfully, but these errors were encountered: