All the examples I can find are mono, with CHANNELS = 1
. How do you read stereo or multichannel input using the callback method in PyAudio and convert it into a 2D NumPy array or multiple 1D arrays?
For mono input, something like this works:
def callback(in_data, frame_count, time_info, status):
global result
global result_waiting
if in_data:
result = np.fromstring(in_data, dtype=np.float32)
result_waiting = True
else:
print('no input')
return None, pyaudio.paContinue
stream = p.open(format=pyaudio.paFloat32,
channels=1,
rate=fs,
output=False,
input=True,
frames_per_buffer=fs,
stream_callback=callback)
But does not work for stereo input, the result
array is twice as long, so I assume the channels are interleaved or something, but I can't find documentation for this.