Thursday, May 16, 2013

Reading WAV file info with Python

The Python standard library comes with a module called It allows you to read and write WAV format audio files.

Here is an example of reading WAV file info with Python:

import wave

wavf ='horse.wav', 'r')
print wavf.getnchannels()
print wavf.getsampwidth()
print wavf.getframerate()
print wavf.getnframes()
print wavf.getcompname()

The above code prints the number of channels (mono or stereo), the sampling width, the frame rate, the number of frames, and the name of the compression type (if any) of the WAV file horse.wav.

You can also write WAV files, but you need to know what data to write.

Wikipedia entry for WAV:

- Vasudev Ram

No comments: