To find frequencies from an audio file in Python, we first need to perform some audio processing techniques such as FFT (Fast Fourier Transform). NumPy provides a convenient way to perform FFT on audio data. Here is an example code that reads an audio file and returns the frequency spectrum.
main.py919 chars29 lines
In this code, we first open the audio file using the wave module. We then read the audio frames using wave.readframes()
and convert the byte array to NumPy array using np.frombuffer()
.
We then apply FFT to each channel using np.fft.rfft()
. The resulting FFT data is stored in fft_frames
. We also obtained the frequency axis using np.fft.rfftfreq()
.
We can then use the resulting fft_frames
and freq_axis
to extract relevant frequency information from the audio file.
gistlibby LogSnag