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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s