I'm trying to run the following code (an example from the PyAudio documentation) on my Mac (OS 10.7.2):
import pyaudio
import sys
chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5
p = pyaudio.PyAudio()
stream = p.open(format = FORMAT,
channels = CHANNELS,
rate = RATE,
input = True,
output = True,
frames_per_buffer = chunk)
print "* recording"
for i in range(0, 44100 / chunk * RECORD_SECONDS):
data = stream.read(chunk)
stream.write(data, chunk)
print "* done"
stream.stop_stream()
stream.close()
p.terminate()
The error that I'm giving is:
Traceback (most recent call last):
File "PyAudioExample.py", line 24, in <module>
data = stream.read(chunk)
File "/Library/Python/2.7/site-packages/pyaudio.py", line 564, in read
return pa.read_stream(self._stream, num_frames)
IOError: [Errno Input overflowed] -9981
I did a search for this error on Google and found that either making the chunk bigger or smaller could help. I tried this and it made no difference. I also tried adding in the following code to catch an overload exception:
try:
data = stream.read(chunk)
except IOError as ex:
if ex[1] != pyaudio.paInputOverflowed:
raise
data = '\x00' * chunk
That avoided the error, but instead of outputting my input audio, I heard a bunch of loud clicking.
To troubleshoot, I commented out the output=True line and the program ran fine, but did not output anything. I commented out the input=True and read in a Wave file instead and the stream was able to output the audio. I tried creating 2 streams, one for input and one for output, and that didn't work either.
Is there something else that I can do to avoid this error?
i run into the same situation when i manually install pyaudio (built portaudio from source), a not so perfect workaround is to download the pyaudio for Apple Mac OS X (Universal) install it, which will only install it for python 2.6 and previous version. if you run your code with /usr/bin/python2.6, then you are done. but if you really want 2.7, copy the installed module (pyaudio.py, _portaudio.so) to the 2.7 folder /Library/Python/2.7/site-packages/.
i donnot know why it does not work building the module from source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With