spatialaudio / python-sounddevice

:sound: Play and Record Sound with Python :snake:
https://python-sounddevice.readthedocs.io/
MIT License
1.05k stars 149 forks source link

Question about two devices record at same time #430

Open xiaoli1996 opened 2 years ago

xiaoli1996 commented 2 years ago

Hi, this is the code from https://github.com/spatialaudio/python-sounddevice/issues/338, operating system is windows10.

from queue import Queue

from sounddevice import InputStream
from soundfile import SoundFile
import sounddevice as sd

fs = 32000
channels = 1
device1 = 1
device2 = 2

#print("default.device:\n", sd.default.device)
print("devices list:\n", sd.query_devices())
#print(sd.query_hostapis())

def create_callback(q):
    def callback(data, frames, time, status):
        if status:
            print(status)
        q.put(data.copy())
    return callback

q1 = Queue()
q2 = Queue()

stream1 = InputStream(
    device=device1,
    samplerate=fs,
    channels=channels,
    callback=create_callback(q1),
)
stream2 = InputStream(
    device=device2,
    samplerate=fs,
    channels=channels,
    callback=create_callback(q2),
)

sf1 = SoundFile(
    file=f"rec_device_{device1}.wav",
    mode="w",
    samplerate=int(stream1.samplerate),
    channels=stream1.channels,
)
sf2 = SoundFile(
    file=f"rec_device_{device2}.wav",
    mode="w",
    samplerate=int(stream2.samplerate),
    channels=stream2.channels,
)

with sf1, sf2:
    with stream1, stream2:
        print("press Ctrl+C to stop the recording")
        try:
            while True:
                sf1.write(q1.get())
                sf2.write(q2.get())
        except KeyboardInterrupt:
            print("\nInterrupted by user.")

I am listing devices with sound device:

   0 Microsoft Sound Mapper - Input, MME (2 in, 0 out)
>  1 ZenGo SC USB Audio Driver Recor, MME (2 in, 0 out)
   2 ZenGo SC USB Audio Driver Recor, MME (2 in, 0 out)
   3 ZenGo SC USB Audio Driver Recor, MME (2 in, 0 out)
   4 ZenGo SC USB Audio Driver Recor, MME (2 in, 0 out)
   5 Microsoft Sound Mapper - Output, MME (0 in, 2 out)
<  6 ZenGo SC USB Audio Driver Playb, MME (0 in, 2 out)
   7 ZenGo SC USB Audio Driver Playb, MME (0 in, 2 out)
   8 Q2490W1 (NVIDIA High Definition, MME (0 in, 2 out)
   9 ZenGo SC USB Audio Driver Playb, MME (0 in, 2 out)
  10 ZenGo SC USB Audio Driver Playb, MME (0 in, 2 out)
  11 Digital Audio (S/PDIF) (High De, MME (0 in, 2 out)
  12 SPDIF Out (HD Audio SPDIF out), Windows WDM-KS (0 in, 2 out)
  13 Output (NVIDIA High Definition Audio), Windows WDM-KS (0 in, 2 out)
  14 ZenGo SC USB Audio Driver Playback 7/8 (ZenGo SC USB Audio Driver Playback 7/8), Windows WDM-KS (0 in, 2 out)
  15 ZenGo SC USB Audio Driver Playback 5/6 (ZenGo SC USB Audio Driver Playback 5/6), Windows WDM-KS (0 in, 2 out)
  16 ZenGo SC USB Audio Driver Playback 3/4 (ZenGo SC USB Audio Driver Playback 3/4), Windows WDM-KS (0 in, 2 out)
  17 ZenGo SC USB Audio Driver Playback 1/2 (ZenGo SC USB Audio Driver Playback 1/2), Windows WDM-KS (0 in, 2 out)
  18 ZenGo SC USB Audio Driver Recording 7/8 (ZenGo SC USB Audio Driver Recording 7/8), Windows WDM-KS (2 in, 0 out)
  19 ZenGo SC USB Audio Driver Recording 5/6 (ZenGo SC USB Audio Driver Recording 5/6), Windows WDM-KS (2 in, 0 out)
  20 ZenGo SC USB Audio Driver Recording 3/4 (ZenGo SC USB Audio Driver Recording 3/4), Windows WDM-KS (2 in, 0 out)
  21 ZenGo SC USB Audio Driver Recording 1/2 (ZenGo SC USB Audio Driver Recording 1/2), Windows WDM-KS (2 in, 0 out)

but the rec_device_2.wav is licence, Sincerely thank you for your help! rec_devices_2

mgeier commented 2 years ago

Maybe that's just not supported by PortAudio or the device driver or the hardware itself?

I'm wondering why there is no WASAPI device listed.

Is there an ASIO driver available?