I want to know about how to get signal from different channels PC sound card using Python. In one channel, I want to get a simple signal like sine wave and from another, I want to get a square wave.
I know that I can get signal using pyaudio like
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
CHUNK = 1024
p = pyaudio.PyAudio()
stream = p.open(
format=FORMAT,
channels=CHANNELS,
rate=RATE, input=True,
frames_per_buffer=CHUNK) #I get one signal
But using this method I can only get one signal at a time (stream), and I would need to get two simultaneous signals (two "stream").
I was able to solve splitting the list in two and changing CHANNELS=2
if signal
is the list I get from the pyaudio function,
signal[::2]
is a channel and signal[1::2
] is another.
There's a exemple below:
sinal = np.frombuffer(stream.read(CHUNK, exception_on_overflow=False), np.int16)
sinal[::2] #from channel 1 for exemple
sinal[1::2] #from channel 2 for exemple