Add your id to the device output and input
Greetings, there is a code on the link,
import sounddevice as sd
duration = 5.5 # seconds
def callback(indata, outdata, frames, time, status):
if status:
print(status)
outdata[:] = indata
with sd.Stream(channels=2, callback=callback):
sd.sleep(int(duration * 1000))
and it suits me completely, I just didn't understand how to enter my equipment IDs, I want to output the signal from the microphone to a virtual cable. Id = 3
You can provide the desired interface with the device= parameter (see https://python-sounddevice.readthedocs.io/en/0.4.3/api/streams.html#sounddevice.Stream).
with sd.RawStream(device=10, channels=2, dtype='int24', callback=callback): <-----------
When I substitute Device = 10 it gives an error.
File "C:\Users\karpo\AppData\Local\Programs\Python\Python39\Lib\site-packages\sounddevice.py", line 2741, in _check
raise PortAudioError(errormsg, err)
sounddevice.PortAudioError: Error opening RawStream: Invalid number of channels [PaErrorCode -9998]
I don't know formats or how many channels your respective input and output interfaces (you will have to provide both names or IDs) support. But https://github.com/spatialaudio/python-sounddevice/blob/0.4.3/examples/wire.py seems to do everything you need. Try to find a working configuration with that implementation (sd.query_devices() should help) and then simplify / adapt the code for your purposes.
sd.default.samplerate = None sd.default.device = None, 7
sd.default.device = input(None = default) , output
I found the answer here
https://python-sounddevice.readthedocs.io/en/0.3.11/#sounddevice.default
Just to clarify: you can do both things mentioned above, both should work:
- use
device=mydeviceordevice=(myinputdevice, myoutputdevice)in the stream constructor - use
sd.default.device = mydeviceorsd.default.device = myinputdevice, myoutputdevicebefore you create your stream (either directly or via some helper function likeplayrec())
I either case you can use None to get the default device.
You can specify your devices either by their numeric ID or by (space-separated) substring(s).