[Tutor] Python audio help needed

Tim tim.ronning at start.no
Fri Oct 17 18:19:24 EDT 2003


Hello list, and greetings from Norway

I'm new to this list and to Python (obviously since I'm asking questions 
here..)

In paralell with learning from books, online training, etc, I have also 
started my own little project. I want to build a dead simple mp3 player 
using pymad (libmad) library and PyQt when I get the basics to work.

I started out with this little script, supplied by the author to show how 
to use pymad.

#!/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))

My first problem, I don't have module ao! Couldn't find on the net so I'm 
trying to acomplish the same with module ossaudiodev. After some study in 
the Python docs I now have this script.

#!/usr/bin/env python
import mad, ossaudiodev, sys

mf = mad.MadFile(sys.argv[1])
dev = ossaudiodev.open('/dev/audio0', "w")
rate=mf.samplerate()
#print rate
dev.setfmt(505)
dev.channels(2)
dev.speed(rate)
while 1:
    buf = mf.read()
    if buf is None:
        break
    dev.write(buf)

This actually plays the commandline supplied mp3 file, but! It sound's like 
something out of a seventees horror movie. It's extremely slow and with a 
lot of noise. I have a feeling that it has something to do with the 
setfmt() but I'm not sure. I'm running with ALSA drivers (with OSS support) 
so in theory it should work, but again I'm not sure. When I run getfmts() 
the result I'm getting back from the sound device is bitmask 505. The 
device is a Creative Live! 5.1 (ALSA emu10k1)

Can anyone help me out here. Is there an ALSA audio module out there 
somewhere? Or should I set some other value to setfmt() All help is greatly 
appriciated.

Best regards
Tim

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/



More information about the Tutor mailing list