PyAudio, how to determine the frequency and amplitude during recording?

I used the PyAudio default recording example and added numpy and scipy. However, I can use scipy.io.wavefile.read('FILE.wav') after writing the file, and it also gives me this random tuple, for example: (44100, array([[ 0, 0], [-2, 0], [ 0, -2], ..., [-2, -2], [ 1, 3], [ 2, -1]], dtype=int16)) . What does this array give, and do you know how else you can get the frequency / amplitude of each frame of the wav file, preferably during recording?

+4
source share
1 answer

An array is not random data, it is the wave data of your stereo sound, and 44100 is the sampling frequency. use the following code to build the left channel wave:

 import scipy.io.wavfile as wavfile import numpy as np import pylab as pl rate, data = wavfile.read('FILE.wav') t = np.arange(len(data[:,0]))*1.0/rate pl.plot(t, data[:,0]) pl.show() 

To get the frequency and amplitude of the wave, do FFT. Following the code graph, the power of each frequency bin:

 p = 20*np.log10(np.abs(np.fft.rfft(data[:2048, 0]))) f = np.linspace(0, rate/2.0, len(p)) pl.plot(f, p) pl.xlabel("Frequency(Hz)") pl.ylabel("Power(dB)") pl.show() 
+10
source

All Articles