Reputation: 193
I have 2 sound cards I have to take inputs from, process it and feed to the output of the third card. I assume that sounddevice
lib is the best option for that purpose because it directly works with numpy
arrays which are extremely comfortable to work with. But there are two issues I've met by now:
1. I can't understand how to connect to 2 (and more) inputs from different cards in one stream (or may be it is possible to open multiple streams)
2. When trying to start an output stream with predefined device I get an error:
def callback(indata, outdata, frames, time, status):
outdata[:, 1] = data
with sd.Stream(device = 1, channels=2, callback=callback):
print(' ')
sounddevice.PortAudioError: Error opening Stream: Invalid number of channels [PaErrorCode -9998]
I suppose that's because of Core Audio channel mapping on my MacBook, which has these audio config:
0 Built-in Input, Core Audio (2 in, 0 out)
1 Built-in Output, Core Audio (0 in, 2 out)
But I can not beat that problem myself.
Thanks in advance
Upvotes: 1
Views: 3388
Reputation: 4894
It's not possible to have a single stream with multiple input or multiple output devices, see also https://stackoverflow.com/a/39919494/.
However, you might be able to combine two devices in your macOS audio settings (look for "aggregate device").
The error you are showing happens because you are using a sd.Stream
, which has both input and output. Specifying channels=2
means that the number of input and output channels are both 2. But you are just providing a single device with device=1
, which doesn't have any input channels, leading to the given error message.
With CoreAudio you can normally just use the default devices, but if you want to specify the device numbers explicitly, you have to specify the correct input and output devices like this:
device=[0, 1]
Upvotes: 2