Python Audio Files


Python can read, write and play sound files. The following scripts can run under Windows and Ubuntu.

* * *


Each script requires the utility module

* * *

wav Files

Here is an example for writing and playing a wav file:

Here is an example for reading and playing a wav file and for displaying its FFT magnitude: This script also has an option to convert the wav file to a time history in ASCII text format.

The audio scripts determine whether the operating system is Windows or Linux.

The sound is played using:

winsound.PlaySound for Windows systems
pygame for Linux

* * *

mp3 Files

Here is an mp3 player:

* * *


python-pygame can be installed from the Ubuntu Software Center

There are other methods for playing sound files in Python, including SFML, Snack, ossaudiodev, pyglet, PyMedia and wxPython.

See also: Matlab Fun with Sound Files

* * *

Tom Irvine