编程语言
首页 > 编程语言> > python – 在pyaudio中使用rate / format / chunk中的任何其他值给出错误:[Errno Input overflowed] -9981

python – 在pyaudio中使用rate / format / chunk中的任何其他值给出错误:[Errno Input overflowed] -9981

作者:互联网

操作系统:Mac OSX 10.7.5
PythonPython 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

解决方法:

如果要检查操作系统和硬件是否支持所需的格式,通道,速率等设置,请执行以下操作:

import pyaudio
soundObj = pyaudio.PyAudio()

# Learn what your OS+Hardware can do
defaultCapability = soundObj.get_default_host_api_info()
print defaultCapability

# See if you can make it do what you want
isSupported = soundObj.is_format_supported(input_format=pyaudio.paInt8, input_channels=1, rate=22050, input_device=0)
print isSupported

isSupported将为True,因为您的系统可以处理您的设置.内存溢出错误可能是由于某些操作系统硬件问题引起的.您必须检查您的默认主机API实际可以执行的操作.您不需要通过“流类”“打开”和“关闭”soundObj来查询它.

看看这个问题:PyAudio Input overflowed

有关其他pyaudio文档和帮助,请访问:

http://people.csail.mit.edu/hubert/pyaudio/docs/

编辑:

事实证明,“Errno输入溢出–9981”并不是一个小问题:http://trac.macports.org/ticket/39150

我看到你有最新的portaudio版本(19.20111121),但19.20111121_4声称修复了这个bug.看看升级portaudio是否有效.

标签:python,microphone,pyaudio,portaudio
来源: https://codeday.me/bug/20190901/1779849.html