I'm trying to get the frequencies from the array generated from pyAudio's callback().
def callback(in_data, frame_count, time_info, flag):
audio_data = np.fromstring(in_data, dtype=np.float32)
freq_data = np.fft.fft(audio_data)
freq = np.abs(freq_data)
# Operations here
recovered_signal = np.fft.ifft(filtered_freq).astype(np.float32).tostring()
I'm getting a 2048 length array, and am not sure how to proceed. I've narrowed down what operations I need to do and tried applying FFT to it, but realized that I need to unpack the data, and pyAudio's documentation is a little lacking (much less not even online sometimes).
Part of my problem is I'm not understanding what in_data
is. From what I can tell from research, it's bytes, which numpy converts into an array for me. However, reading an article on signal-processing for python gave me the impression I should be able to extract this into frequencies, and then perform this on it for a basic passband filter.
for f in freq:
if index > LOWCUT and index < HIGHCUT:
if f > 1:
filtered_freq.append(f)
#print(index)
else:
filtered_freq.append(0)
else:
filtered_freq.append(0)
index += 1
I've looked at np.fft.fftfreq
as well, but that also still seems to produce an array of 2048 length, instead of an array containing all the frequencies and their power.
Edit: I know that with two channels the are interweaved, but my issue is mostly not understanding what the converted array by numpy represents and can be used.