Pyaudio:将输入连接到输出时出错

时间:2015-03-24 14:48:01

标签: python portaudio pyaudio intel-edison

我在英特尔Edison主板上试用了pyaudio,但它在内置测试中失败了。单独录制和播放可以正常使用我的设置,但如果我尝试将输入连接到输出,则会出错。

  

文件" wire_full.py",第33行,in       data = stream.read(CHUNK)File" /usr/lib/python2.7/site-packages/pyaudio.py" ;,第605行,正在读取       return pa.read_stream(self._stream,num_frames)IOError:[Errno Input overflowed] -9981

有人知道问题是什么吗?

以下是在pyaudio中输出到输出的示例代码:

""" 
PyAudio Example: Make a wire between input and output (i.e., record a 
few samples and play them back immediately). 


This is the full duplex version. 
"""  


import pyaudio  
import sys  


CHUNK = 1024  
WIDTH = 2  
CHANNELS = 2  
RATE = 44100  
RECORD_SECONDS = 5  


if sys.platform == 'darwin':  
    CHANNELS = 1  


p = pyaudio.PyAudio()  


stream = p.open(format=p.get_format_from_width(WIDTH),  
                channels=CHANNELS,  
                rate=RATE,  
                input=True,  
                output=True,  
                frames_per_buffer=CHUNK)  


print("* recording")  


for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):  
    data = stream.read(CHUNK)  
    stream.write(data, CHUNK)  


print("* done")  


stream.stop_stream()  
stream.close()  

p.terminate()

2 个答案:

答案 0 :(得分:2)

我通过将CHUNK大小更改为512来解决它。偶尔会出现相同的错误,但至少它在大部分时间都有效。

如果知道为什么会这样,或者我怎么可能完全删除错误?

<强>更新

好的,所以我用try ...包围了读/写代码,除了将CHUNK大小降低到512,现在它正常工作没有任何错误。如果我使用1024作为CHUNK大小,会丢失很多帧并且声音质量很差。

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):  
    try:
        data = stream.read(CHUNK)  
        stream.write(data, CHUNK)  
    except:
        pass

感谢@Meta的线索! :)

答案 1 :(得分:0)

此代码记录音频并立即播放:

Caused by: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated