FFT for Spectrograms in Python FFT for Spectrograms in Python python python

FFT for Spectrograms in Python


Python's wave library will let you import the audio. After that, you can use numpy to take an FFT of the audio.

Then, matplotlib makes very nice charts and graphs - absolutely comparable to MATLAB.

It's old as dirt, but this article would probably get you started on almost exactly the problem you're describing (article in Python of course).


Loading WAV files is easy using audiolab:

from audiolab import wavreadsignal, fs, enc = wavread('test.wav')

or for reading any general audio format and converting to WAV:

from audiolab import Sndfilesound_file = Sndfile('test.w64', 'r')signal = wave_file.read_frames(wave_file.nframes)

The spectrogram is built into PyLab:

from pylab import *specgram(signal)

Specifically, it's part of matplotlib. Here's a better example.


from pylab import *specgram(signal)

is the easiest. Also quite handy in this context:

subplot

But be warned: Matplotlib is very slow but it creates beautiful images. You should not use it for demanding animation, even less when you are dealing with 3D