Converting chunk to numpy array

#4 · closed · 3 comments

View on GitHub ↗

Wei1234c

I use the code below and it seems fine. data = stream.read(CHUNK) data_np = np.fromstring(data, np.int16) <=== matching "FORMAT = pyaudio.paInt16"

Comments

rudrathegreat

What's the issue?

rudrathegreat

If the issue is that the data is not going in the array, then try the following - ``` Python data = stream.read(CHUNK) # Binary Data data_int = struct.unpack(str(2 * CHUNK) + 'B', data) # Integer Data data_np = np.array(data_int, dtype='b')[::2] + 128 # Data in Array ```

Wei1234c

Thanks !