play mp3 files from python

Tim Ronning tim.ronning at start.no
Sat Oct 25 18:45:20 EDT 2003


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

> 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

Adam,

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 = mf.read()
    if buf is None:
        break
    dev.play(buf, 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: http://www.opera.com/m2/





More information about the Python-list mailing list