BlogGalleryAbout meContact
Jaganadh's bookshelf: read

Python Text Processing with NTLK 2.0 CookbookPython 2.6 Text Processing Beginners Guide

More of Jaganadh's books »
Jaganadh Gopinadhan's  book recommendations, reviews, quotes, book clubs, book trivia, book lists
Ubuntu GNU/Linux I am nerdier than 94% of all people. Are you a nerd? Click here to take the Nerd Test, get nerdy images and jokes, and write on the nerd forum! Python


Plotting wave form and spectrogram the pure Python way

In one of my earlier post we discussed how to plot spectrogram with 'scikits audiolab' and python. One of my friend asked me whether it is possible to do without 'audiolab'. So I started exploring Python wave reading module and wrote another piece of code to plot spectrogram and waveform. In this program I reduced some dependency also. While using 'audiolab',  'numpy' and 'struct' were imported in the program. In this program only 'pylab' and 'wave' modules are imported. This program will plot both waveform and spectrogram in same window.
Here is the code.

=== Code begin ===
#!/usr/bin/env python
import sys
from pylab import *
import wave

def show_wave_n_spec(speech):
    spf =,'r')
    sound_info = spf.readframes(-1)
    sound_info = fromstring(sound_info, 'Int16')

    f = spf.getframerate()
    title('Wave from and spectrogram of %s' % sys.argv[1])

    spectrogram = specgram(sound_info, Fs = f, scale_by_freq=True,sides='default')

fil = sys.argv[1]

=== Code End ======

To run the program copy and paste the code into a file Run python your_wav.wav .

I just run the program on a small .wav file . The result is shown below.



No new comments allowed (anymore) on this post.