【发布时间】:2015-03-26 07:22:42
【问题描述】:
我试图在我的 RaspberryPi 模型 B 板上的 Rasbian 上执行 PyAudio python 捕获程序,但出现错误:
Traceback (most recent call last):
File "/home/pi/pythonsound/record.py", line 35, in <module>
data = stream.read(CHUNK)
File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 605, in read
return pa.read_stream(self._stream, num_frames)
IOError: [Errno Input overflowed] -9981
还有一些其他建议可用但无效 这是我尝试过的, 这是代码
import pyaudio
import wave
import sys
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("* recording")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
print("* done recording")
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
这是我的 USB 声卡设备信息,
{'defaultSampleRate': 44100.0,
'defaultLowOutputLatency': 0.011609977324263039,
'defaultLowInputLatency': 0.011609977324263039,
'maxInputChannels': 1L,
'structVersion': 2L,
'hostApi': 0L,
'index': 0,
'defaultHighOutputLatency': 0.046439909297052155,
'maxOutputChannels': 2L,
'name': u
'USB PnP Sound Device: USB Audio (hw:0,0)',
'defaultHighInputLatency': 0.046439909297052155}
你能指导我解决这个问题吗?
【问题讨论】:
-
通常,输入溢出意味着数据到达的速度快于计算机读取数据的能力。你能知道你是否收到了任何数据吗?
-
@HeatfanJohn 在命令终端上它正在接收来自此命令的音频输入
arecord -D plug:default -f S16_LE -c 1 -r 16000 -d 300 a.wav -
@HeatfanJohn 我如何在 python 上知道它是否真的在接收数据,尽管它显示了上述错误
-
可能在 python 脚本中的
data = stream行之前添加一个print i。 -
@HeatfanJohn 当我在 python 脚本
* recording 0 1 Traceback (most recent call last): File "/home/pi/pythonsound/myaudio01JAN27.py", line 25, in <module> data = stream.read(CHUNK) File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 605, in read return pa.read_stream(self._stream, num_frames) IOError: [Errno Input overflowed] -9981中的data=stream之前添加print i行时,我得到了这个输出
标签: python audio raspbian ioerror