play mp3 files from python

Tim Ronning tim.ronning at
Sun Oct 26 00:45:20 CEST 2003

På Sat, 25 Oct 2003 19:29:02 GMT, skrev Adam Endicott <x at>:

> I got all excited when iTunes was released for Windows. Then I was 
> quickly disappointed when I found out it only works for XP or 2000 (I'm 
> out of luck with 98 or ME). So I figured, hey, I've been wanting to write 
> my own python player anyway, why not make a PyTunes?
> I hit my first stumbling block almost immediately. I can't seem to find 
> an easy module that will let me play an mp3 file. I'm sure it must be out 
> there, but I can't figure it out (I'm a newbie to all but the most simple


I have just done the same thing. Here's a solution for you. Pymad org. code

#!/usr/bin/env python
import mad, ao, sys
mf = mad.MadFile(sys.argv[1])
dev = ao.AudioDevice('oss', rate=mf.samplerate())
while 1:
    buf =
    if buf is None:
        break, len(buf))

You need to get the pymad module, libmad mp3 decoder and the ao module. Do 
a google and you will find them all.

Best of luck

Tim Ronning

Using M2, Opera's revolutionary e-mail client:

More information about the Python-list mailing list