I want to use sounddevice to display signals received from multiple microphones in real time

25 Views Asked by At

I used an audio interface called "steinberg UR824" and connected two microphones.

I then downloaded the asio driver and tried to create a program to display the signals received from multiple microphones in real time using a library called "sounddevice" that can control the asio device. (This time, the number of microphones is set to two, so two real-time waveforms are displayed.)

However, I cannot do it well because I do not understand the specification of "InputStream".

I tried setting the value of "channels" in the "InputStream" argument to 2, but only one microphone responded.

I have included a list of my connected devices and the source code below, so please let me know what I need to fix to input the two microphones.

#####devices list#####
   0 Microsoft Sound Mapper - Input, MME (2 in, 0 out)
   1 Line (Steinberg UR824), MME (2 in, 0 out)
   2 Microsoft Sound Mapper - Output, MME (0 in, 2 out)
   3 Line (Steinberg UR824), MME (0 in, 2 out)
   4 Realtek Digital Output (Realtek, MME (0 in, 2 out)
   5 プライマリ サウンド キャプチャ ドライバー, Windows DirectSound (2 in, 0 out)
   6 Line (Steinberg UR824), Windows DirectSound (2 in, 0 out)
   7 プライマリ サウンド ドライバー, Windows DirectSound (0 in, 2 out)
   8 Line (Steinberg UR824), Windows DirectSound (0 in, 2 out)
   9 Realtek Digital Output (Realtek High Definition Audio), Windows DirectSound (0 in, 8 out)
  10 Generic Low Latency ASIO Driver, ASIO (0 in, 2 out)
  11 Realtek ASIO, ASIO (2 in, 2 out)
* 12 Yamaha Steinberg USB ASIO, ASIO (24 in, 26 out)
  13 Realtek Digital Output (Realtek High Definition Audio), Windows WASAPI (0 in, 2 out)
  14 Line (Steinberg UR824), Windows WASAPI (0 in, 2 out)
  15 Line (Steinberg UR824), Windows WASAPI (2 in, 0 out)
  16 ライン入力 (Realtek HD Audio Line input), Windows WDM-KS (2 in, 0 out)
  17 SPDIF Out (Realtek HDA SPDIF Out), Windows WDM-KS (0 in, 2 out)
  18 Speakers (Realtek HD Audio output), Windows WDM-KS (0 in, 8 out)
  19 ステレオ ミキサー (Realtek HD Audio Stereo input), Windows WDM-KS (2 in, 0 out)
  20 マイク (Realtek HD Audio Mic input), Windows WDM-KS (2 in, 0 out)
  21 Line (), Windows WDM-KS (2 in, 0 out)
  22 Line (), Windows WDM-KS (0 in, 2 out)
#####source code#####
import sounddevice as sd
import numpy as np
from matplotlib.animation import FuncAnimation
import matplotlib.pyplot as plt

device_list = sd.query_devices()
sd.default.device = 12 
print(device_list)


def callback(indata, frames, time, status):
    # indata.shape=(n_samples, n_channels)
    global plotdata
    data = indata[:, 0]
    shift = len(data)
    plotdata = np.roll(plotdata, -shift, axis=0)
    plotdata[-shift:] = data


def update_plot(frame):
    """This is called by matplotlib for each plot update.
    """
    global plotdata
    line.set_ydata(plotdata)
    return line,


fs = 48000
length = fs
plotdata = np.zeros((length))
fig, ax = plt.subplots()
line, = ax.plot(plotdata)
ax.set_ylim([-1.0, 1.0])
ax.set_xlim([0, length])
ax.yaxis.grid(True)
fig.tight_layout()

stream = sd.InputStream(
    samplerate=fs,
    channels=2,
    dtype='float32',
    callback=callback
)
print(stream)
ani = FuncAnimation(fig, update_plot, interval=3, blit=True)
with stream:
    plt.show()

For now, I'd like to get the two microphones recognized first, so if you know what to do, please answer.

0

There are 0 best solutions below