操作系统:Mac OSX 10.7.5 Python:Python 2.7.3(自制) pyaudio:0.2.7 portaudio:19.20111121(自制-portaudio)
以下脚本输出以下内容并显示我遇到的问题:
#!/usr/bin/env python
import pyaudio
from pprint import pprint
p = pyaudio.PyAudio()
# SUCCEEDS
pprint(p.is_format_supported(input_format=pyaudio.paInt8,input_channels=1,rate=44100,input_device=0)) # => True
try:
stream = p.open(format=pyaudio.paInt8,channels=1,rate=44100,input=True,frames_per_buffer=1024)
data = stream.read(1024)
except IOError as e:
print 'This never happens: '+str(e)
# FAILS
pprint(p.is_format_supported(input_format=pyaudio.paInt8,input_channels=1,rate=22050,input_device=0)) # => True
try:
stream = p.open(format=pyaudio.paInt8,channels=1,rate=22050,input=True,frames_per_buffer=1024)
data = stream.read(1024)
except IOError as e:
print 'This fails: '+str(e)
# FAILS
pprint(p.is_format_supported(input_format=pyaudio.paInt8,input_channels=1,rate=22050,input_device=0)) # => True
try:
stream = p.open(format=pyaudio.paInt8,channels=1,rate=22050,input=True,frames_per_buffer=512)
data = stream.read(1024)
except IOError as e:
print 'This also fails: '+str(e)
# FAILS
pprint(p.is_format_supported(input_format=pyaudio.paInt8,input_channels=1,rate=11025,input_device=0)) # => True
try:
stream = p.open(format=pyaudio.paInt8,channels=1,rate=11025,input=True,frames_per_buffer=512)
data = stream.read(1024)
except IOError as e:
print 'This also fails as well: '+str(e)
stream.stop_stream()
stream.close()
p.terminate()
以上输出如下:
True
True
This fails: [Errno Input overflowed] -9981
True
This also fails: [Errno Input overflowed] -9981
True
This also fails as well: [Errno Input overflowed] -9981
尽管上面的注释表明stop_stream()和close()没有修复它,但是像这样关闭它们对我来说很有用:
这将为不支持的速率(异常)提供预期结果:
如果要检查您的操作系统和硬件是否支持所需的格式、频道、速率等设置,请执行以下操作:
isSupported
将是True
,因为您的系统可以处理您的设置。内存溢出错误可能是由于某些OS+硬件问题造成的。您必须检查默认的主机API实际上可以做什么。您不需要通过“stream类”来“打开”和“关闭”查询soundObj
。看看这个问题:PyAudio Input overflowed
有关其他pyaudio文档和帮助,请访问:
http://people.csail.mit.edu/hubert/pyaudio/docs/
编辑:
原来,“Errno Input overflowed-9981”不是一个小问题:http://trac.macports.org/ticket/39150
我看到你有最新的portaudio版本(19.20111121),但是19.20111121_4声称已经修复了这个错误。看看升级portaudio是否有效。
相关问题 更多 >
编程相关推荐