Python Audio Files

Introduction

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

* * *

Utility

Each script requires the utility module tompy.py

* * *

wav Files

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

Here is an example for reading and playing a wav file and for displaying its FFT magnitude: wav_player.py. 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: mp3_player.py

* * *

pygame

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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s