我正在尝试从音频流中获取样本并将它们放入共享队列中。我有另一个从这个队列中提取的进程。
当我运行时,我收到此错误:
* recording
Traceback (most recent call last):
File "record.py", line 43, in <module>
data = stream.read(CHUNK)
File "/Library/Python/2.7/site-packages/pyaudio.py", line 605, in read
return pa.read_stream(self._stream, num_frames)
IOError: [Errno Input overflowed] -9981
编辑:显然问题已经存在了一段时间没有发布解决方案(我尝试了他们的建议):
获取 IOError: [Errno Input overflowed] -9981 将 PyAudio Stream 输入和输出设置为 True
- https://github.com/jeysonmc/python-google-speech-scripts/issues/1
这是(简化的)代码:
import pyaudio
import wave
import array
import time
from multiprocessing import Queue, Process
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 2
p = pyaudio.PyAudio()
left = Queue()
right = Queue()
def other(q1, q2):
while True:
try:
a = q1.get(False)
except Exception:
pass
try:
b = q2.get(False)
except Exception:
pass
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("* recording")
Process(target=other, args=(left, right)).start()
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
byte_string = ''.join(data)
nums = array.array('h', byte_string)
for elt in nums[1::2]:
left.put(elt)
for elt in nums[0::2]:
right.put(elt)
print("* done recording")
stream.stop_stream()
stream.close()
print "terminated"
我究竟做错了什么?我在 Mac OSX 和 Python 2.7 上,我安装portaudio
并homebrew
尝试了pip
`pyaudio 和 dmg 安装,但都没有运气。