markjay4k/Audio-Spectrum-Analyzer-in-Python

Converting chunk to numpy array

Wei1234c opened this issue · 3 comments

I use the code below and it seems fine.

data = stream.read(CHUNK)
data_np = np.fromstring(data, np.int16) <=== matching "FORMAT = pyaudio.paInt16"

What's the issue?

If the issue is that the data is not going in the array, then try the following -

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

Thanks !