获取 IOError: [Errno Input overflowed] -9981 将 PyAudio Stream 输入和输出设置为 True 时 [英] Getting IOError: [Errno Input overflowed] -9981 when setting PyAudio Stream input and output to True
问题描述
我正在尝试在我的 Mac(操作系统 10.7.2)上运行以下代码(来自 PyAudio 文档的示例):
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()
我给出的错误是:
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
我在 Google 上搜索了此错误,发现将块变大或变小都会有所帮助.我试过了,没有什么区别.我还尝试添加以下代码来捕获重载异常:
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.
为了排除故障,我注释掉了 output=True 行,程序运行良好,但没有输出任何内容.我注释掉 input=True 并改为读取 Wave 文件,并且流能够输出音频.我尝试创建 2 个流,一个用于输入,一个用于输出,但也没有用.
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?
推荐答案
当我手动安装 pyaudio(从源代码构建 portaudio)时,我遇到了同样的情况,一个不太完美的解决方法是下载 Apple Mac OS X(通用) 的 pyaudio安装它,它只会为 python 2.6 和以前的版本安装它.如果你用/usr/bin/python2.6 运行你的代码,那么你就完成了.但如果你真的想要 2.7,请将已安装的模块(pyaudio.py、_portaudio.so)复制到 2.7 文件夹/Library/Python/2.7/site-packages/.
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.
这篇关于获取 IOError: [Errno Input overflowed] -9981 将 PyAudio Stream 输入和输出设置为 True 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!