chunk_length = len(result) / channels
assert chunk_length == int(chunk_length)
result = np.reshape(result, (chunk_length, channels))
return result

def encode(signal):
    """
    Convert a 2D numpy array into a byte stream for PyAudio
    Signal should be a numpy array with shape (chunk_size, channels)
    """
interleaved = signal.flatten()
out_data = interleaved.astype(np.float32).tostring()
return out_data
Преобразование многоканального PyAudio в массив NumPy