play mp3 files from python

Discussion in 'Python' started by Adam Endicott, Oct 25, 2003.

  1. 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.
     
    Adam Endicott, Oct 25, 2003
    #1
    1. Advertising

  2. In article <>,
    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.
     
    Adam Endicott, Oct 25, 2003
    #2
    1. Advertising

  3. Adam Endicott

    Tim Ronning Guest

    PÃ¥ Sat, 25 Oct 2003 19:29:02 GMT, skrev Adam Endicott <>:

    > 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/
     
    Tim Ronning, Oct 25, 2003
    #3
  4. Adam Endicott

    JanC Guest

    Adam Endicott <> 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
     
    JanC, Oct 26, 2003
    #4
  5. Adam Endicott

    Anand Pillai Guest

    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 <> wrote in message news:<Xns9420347E5763AJanC@213.118.75.228>...
    > Adam Endicott <> 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...
     
    Anand Pillai, Oct 27, 2003
    #5
  6. Adam Endicott

    Jesper Olsen Guest

    I think Snack also supports mp3 - at least the documentation says so

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

    Jesper



    Adam Endicott <> wrote in message news:<>...
    > 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.
     
    Jesper Olsen, Oct 27, 2003
    #6
  7. Adam Endicott

    Paul Foley Guest

    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>"))
     
    Paul Foley, Oct 27, 2003
    #7
  8. (Anand Pillai) wrote in
    news::

    > 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 <> wrote in message
    > news:<Xns9420347E5763AJanC@213.118.75.228>...
    >> Adam Endicott <> 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 <>
     
    Chris Liechti, Oct 27, 2003
    #8
  9. On Tue, 28 Oct 2003 04:26:12 +1300, rumours say that Paul Foley
    <> 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
     
    Christos TZOTZIOY Georgiou, Oct 27, 2003
    #9
  10. Adam Endicott

    JanC Guest

    Paul Foley <> 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:

    and on the features page:

    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
     
    JanC, Oct 28, 2003
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Dyer
    Replies:
    6
    Views:
    19,934
    Knute Johnson
    Jan 22, 2006
  2. Asle Frantzen

    Mp3-player - how to play an mp3?

    Asle Frantzen, Jul 8, 2003, in forum: C++
    Replies:
    5
    Views:
    671
    Kelsey Bjarnason
    Jul 22, 2003
  3. el chupacabra
    Replies:
    1
    Views:
    370
    Lucas Raab
    Aug 27, 2005
  4. Andrew

    how to play MP3 files

    Andrew, Mar 8, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    1,570
  5. HY Tech
    Replies:
    0
    Views:
    623
    HY Tech
    Sep 7, 2003
Loading...

Share This Page