Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > play mp3 files from python

Reply
Thread Tools

play mp3 files from python

 
 
Adam Endicott
Guest
Posts: n/a
 
      10-25-2003
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
Python scripts, and I know nothing about audio processing). About an hour
of searching kept turning up the same couple of things (PyGame and
mpg123).

PyGame - tried this, and got it working very easily. It played, but
sounded terrible. I'm using a sample script which I think came from
c.l.py:

mixer.init(44100)
mixer.music.load(filename)
mixer.music.play()
mixer.music.get_busy()

print "Press enter to quit."
raw_input()

Again, that works, but the sound is absolutely terrible. The file I'm
using to test gives me the following information in winamp (in case this
may be the reason).
209kbit (VBR), 7316 frames
44100Hz Joint Stereo
The PyGame documentation in this area seemed pretty sparse to me (as
someone who doesn't know anything about audio files). Is there a way to
tweak the sound?

mpg123 - I saw this referenced a number of times, but I don't know how to
use it. I've never used any C code from Python. Is there a Python wrapper
for this that I could use? I didn't see one, but I may have missed it.

Sorry for the long post, but my main question is, what's the easiest way
to play an mp3 file from Python on a windows system? If one of the above
is my best option, can someone help me with the next step to get it
working?

Thanks in advance for any help.
 
Reply With Quote
 
 
 
 
Adam Endicott
Guest
Posts: n/a
 
      10-25-2003
In article <(E-Mail Removed)>,
http://www.velocityreviews.com/forums/(E-Mail Removed) says...
> 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


Thank you for the quick reply. I found pymad, libmad, and ao, but I can't
get them installed. If I run 'python setup.py build' (or install) for
either pymad or ao, I just get "No 'Setup' file. Perhaps you need to run
the configure script.". So I run config_unix.py not expecting it to work,
and of course it doesn't. I'm on Windows ME. The website isn't much help
for clueless windows users like myself. I can't just put the .c and .h
files in site-packages right? I'm sure I must need *some* python code
somewhere.
 
Reply With Quote
 
 
 
 
Tim Ronning
Guest
Posts: n/a
 
      10-25-2003
På Sat, 25 Oct 2003 19:29:02 GMT, skrev Adam Endicott <(E-Mail Removed)>:

> 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/

 
Reply With Quote
 
JanC
Guest
Posts: n/a
 
      10-26-2003
Adam Endicott <(E-Mail Removed)> schreef:

> 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
> Python scripts, and I know nothing about audio processing).


Bookmarked but never tried this: <http://audiere.sourceforge.net/>
The "features" mention working on Windows and having Python bindings...

--
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
 
Reply With Quote
 
Anand Pillai
Guest
Posts: n/a
 
      10-27-2003
This question has been asked many times here before.

mpg123 is a pretty good player for linux and unix systems
.. Perhaps you can consider writing a python extension for it.
It would benefit the python community I think.

For information on how to write extensions consult the
python documentation, at http://www.python.org/doc/current

-Anand

JanC <(E-Mail Removed)> wrote in message news:<Xns9420347E5763AJanC@213.118.75.228>...
> Adam Endicott <(E-Mail Removed)> schreef:
>
> > 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
> > Python scripts, and I know nothing about audio processing).

>
> Bookmarked but never tried this: <http://audiere.sourceforge.net/>
> The "features" mention working on Windows and having Python bindings...

 
Reply With Quote
 
Jesper Olsen
Guest
Posts: n/a
 
      10-27-2003
I think Snack also supports mp3 - at least the documentation says so

http://www.speech.kth.se/snack/

Jesper



Adam Endicott <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
> Python scripts, and I know nothing about audio processing). About an hour
> of searching kept turning up the same couple of things (PyGame and
> mpg123).
>
> PyGame - tried this, and got it working very easily. It played, but
> sounded terrible. I'm using a sample script which I think came from
> c.l.py:
>
> mixer.init(44100)
> mixer.music.load(filename)
> mixer.music.play()
> mixer.music.get_busy()
>
> print "Press enter to quit."
> raw_input()
>
> Again, that works, but the sound is absolutely terrible. The file I'm
> using to test gives me the following information in winamp (in case this
> may be the reason).
> 209kbit (VBR), 7316 frames
> 44100Hz Joint Stereo
> The PyGame documentation in this area seemed pretty sparse to me (as
> someone who doesn't know anything about audio files). Is there a way to
> tweak the sound?
>
> mpg123 - I saw this referenced a number of times, but I don't know how to
> use it. I've never used any C code from Python. Is there a Python wrapper
> for this that I could use? I didn't see one, but I may have missed it.
>
> Sorry for the long post, but my main question is, what's the easiest way
> to play an mp3 file from Python on a windows system? If one of the above
> is my best option, can someone help me with the next step to get it
> working?
>
> Thanks in advance for any help.

 
Reply With Quote
 
Paul Foley
Guest
Posts: n/a
 
      10-27-2003
On 26 Oct 2003 22:53:17 -0800, Anand Pillai wrote:

> This question has been asked many times here before.
> mpg123 is a pretty good player for linux and unix systems
> . Perhaps you can consider writing a python extension for it.
> It would benefit the python community I think.


Better yet, make something to play Ogg/Vorbis files from Python, if
that's what you want to do, and convert all your mp3s to Vorbis
(http://www.xiph.org)

Smaller files, higher quality, and no license fees.

--
Cogito ergo I'm right and you're wrong. -- Blair Houghton

(setq reply-to
(concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz>"))
 
Reply With Quote
 
Chris Liechti
Guest
Posts: n/a
 
      10-27-2003
(E-Mail Removed) (Anand Pillai) wrote in
news:(E-Mail Removed) om:

> This question has been asked many times here before.
>
> mpg123 is a pretty good player for linux and unix systems
> . Perhaps you can consider writing a python extension for it.
> It would benefit the python community I think.


ure use an existing one:
http://www.tf.hut.fi/~flu/cplay/

altough it uses curses and linux/posix features, probably no option for the
OP.

chris

> For information on how to write extensions consult the
> python documentation, at http://www.python.org/doc/current
>
> -Anand
>
> JanC <(E-Mail Removed)> wrote in message
> news:<Xns9420347E5763AJanC@213.118.75.228>...
>> Adam Endicott <(E-Mail Removed)> schreef:
>>
>> > 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 Python scripts, and I know nothing about audio
>> > processing).

>>
>> Bookmarked but never tried this: <http://audiere.sourceforge.net/>
>> The "features" mention working on Windows and having Python
>> bindings...




--
Chris <(E-Mail Removed)>

 
Reply With Quote
 
Christos TZOTZIOY Georgiou
Guest
Posts: n/a
 
      10-27-2003
On Tue, 28 Oct 2003 04:26:12 +1300, rumours say that Paul Foley
<(E-Mail Removed)> might have written:

>Better yet, make something to play Ogg/Vorbis files from Python, if
>that's what you want to do, and convert all your mp3s to Vorbis
>(http://www.xiph.org)
>
>Smaller files, higher quality, and no license fees.


Let's start a fight over at hydrogenaudio. I'm using the following
attack: "Musepack beats Ogg Vorbis hands down."
Your move
--
TZOTZIOY, I speak England very best,
Ils sont fous ces Redmontains! --Harddix
 
Reply With Quote
 
JanC
Guest
Posts: n/a
 
      10-28-2003
Paul Foley <(E-Mail Removed)> schreef:

> Better yet, make something to play Ogg/Vorbis files from Python, if
> that's what you want to do, and convert all your mp3s to Vorbis


If you look at the link I gave, it says:

Quote:
Audiere is a high-level audio API. It can play Ogg Vorbis, MP3, FLAC,
uncompressed WAV, AIFF, MOD, S3M, XM, and IT files. For audio output,
Audiere supports DirectSound or WinMM in Windows, OSS on Linux and Cygwin,
and SGI AL on IRIX.
and on the features page:

Quote:
* Braindead easy API
* Supported file formats: Uncompressed WAV*, Uncompressed AIFF*, Ogg
Vorbis*, FLAC*, MP3, MOD, S3M, IT, XM (* supports seeking)
* Streaming and buffered audio
* Volume, pan, and pitch shift modification
* Flat tone, square wave, white noise, and pink noise generation
* Runtime enumeration of audio devices and supported file formats
* Custom file streams
* Python, Delphi, Java, XPCOM (JavaScript in Mozilla) bindings
If it works as advertised, this should do what you want...

--
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
3GP to MP3 Convert 3GP to MP3 using 3GP MP3 Converter music-fan DVD Video 0 12-24-2009 04:58 AM
Saving MP3 files to CD as MP3 files Mighty Magpie Computer Information 3 04-07-2008 03:50 PM
Play MP3 files on CD - How? Pete Brown Computer Support 6 11-09-2005 03:39 PM
Is there any module to play mp3 or wav format files? el chupacabra Python 1 08-27-2005 01:22 PM
Mp3-player - how to play an mp3? Asle Frantzen C++ 5 07-22-2003 07:09 AM



Advertisments