我正在尝试通过具有4个USB声卡的Raspberry Pi上的sounddevice模块进行输入输出对。我最多只能建立两个有线频道,但三个频道都无法使用。理想情况下,我想建立最多4通道的实时流(延迟并不重要。)
我使用了callback和with :,似乎可以在两个通道上正常工作。请找到以下代码:
import sounddevice as sd
def wirecall(indata,outdata,*stuff):
#sd.CallbackStop()
outdata[:]=indata
with sd.Stream(device=0,channels=1,callback=wirecall,samplerate=44100):
with sd.Stream(device=1, channels=1, callback=wirecall, samplerate=44100):
while True:
response=input()
if response in ('', 'q', 'Q'):
break
这可以正常工作,但是只要我再添加一个:它就不起作用。这是Raspberry或Sounddevice模块的限制吗?我也尝试过PyAudio,但结果相同。
当我尝试打开以下3个流时,会出现错误消息。
>>> with sd.Stream(device=3,channels=1,callback=wirecall,samplerate=44100):
... with sd.Stream(device=1,channels=1,callback=wirecall,samplerate=44100):
... with sd.Stream(device=2, channels=1,callback=wirecall,samplerate=44100):
... while True:
... response=input()
... if response in ('', 'q', 'Q'):
... break
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "/home/pi/.local/lib/python2.7/site-packages/sounddevice.py", line 1662, in __init__
**_remove_self(locals()))
File "/home/pi/.local/lib/python2.7/site-packages/sounddevice.py", line 780, in __init__
'Error opening {0}'.format(self.__class__.__name__))
File "/home/pi/.local/lib/python2.7/site-packages/sounddevice.py", line 2570, in _check
raise PortAudioError(errormsg, err, hosterror_info)
sounddevice.PortAudioError: Error opening Stream: Unanticipated host error [PaErrorCode -9999]: 'Broken pipe' [ALSA error -32]
>>>