matplotlib provides the convenient function specgram(that performs most of the under-the-hood calculation and plotting for usimport scipy from matplotlib pyplot import specgram sample_ratex scipy io wavfile read(wave_filenameprint sample_ratex shape ( ,specgram(xfs=sample_ratexextent=( , )the wave file we just read was sampled at sample rate of , hz and contains , samples if we now plot the spectrogram for these first seconds of diverse wave fileswe can see that there are commonalities between songs of the same genre