I'm trying to find a Python library that would take an audio file (e.g. .ogg, .wav) and convert it into mp3 for playback on a webpage.
Also, any thoughts on setting its quality for playback would be great.
Thank you.
I'm trying to find a Python library that would take an audio file (e.g. .ogg, .wav) and convert it into mp3 for playback on a webpage.
Also, any thoughts on setting its quality for playback would be great.
Thank you.
Looks like PyMedia does this:
http://pymedia.org/
and some more info here on converting to various formats, whilst setting the bitrate:
http://pymedia.org/tut/recode_audio.html
e.g.
You may use ctypes module to call functions directly from dynamic libraries. It doesn't require you to install external Python libs and it has better performance than command line tools, but it's usually harder to implement (plus of course you need to provide external library).
Another option to avoid installing Python modules for this simple task would be to just exec "lame" or other command line encoder from the Python script (with the popen module.)
I use the Python bindings for gstreamer. It's a bit hard to get started but once you get going nearly anything's possible.
From the command line (from gstreamer's documentation):
The input
filesrc location=...
could be anything gstreamer can play, not just .wav. You could add something called a caps filter to resample to a specific rate before you encode.In your Python program you would use
gst.parse_launch(...)
, get the filesrc and filesink elements, and call setters to change the input and output filenames.Also, the Python Audio Tools should be able to do the job with less need for other libraries, which might be easier if you're doing this on a shared web hosting account. (But admittedly I haven't tried it, so I can't confirm how usable it is.)
I wrote a library designed to do that =D
Easy!
to specify a bitrate, just use the
bitrate
kwarg…