问题
Im coding a music player in python using pyqt and I wanted it to feature mono playback of mp3 files.
I've accomplished that using pygame, as its mixer has a specific parameter channels
that I can set to 1
to get mono playback.
However, pygame mp3 support is limited, so I'm searching for a library that will be able to handle mp3 files AND mono playback.
Currently, I'm using pyaudiere for playback and on its site there's an example of processing the song before playing it, so maybe I could do that to turn the song to mono, but I really have no idea how to accomplish that.
I'd like help on how to code this feature using pyaudiere or any other library that can handle mp3 files.
EDIT
I would also accept a solution in C++, as I can always build a python wrapper using Boost::python
回答1:
IF you want really good Windows support I suspect you might need or find it easier to use a different API for Windows... check these links:
- http://people.csail.mit.edu/hubert/pyaudio/ (cross-platform)
- http://ffmpeg.org/ffmpeg.html (cross-platform)
- http://www.codeproject.com/KB/audio-video/MP3Example.aspx (Windows-specific)
- http://msdn.microsoft.com/en-us/library/windows/desktop/dd743572%28v=vs.85%29.aspx (Windows-specific)
EDIT - most probably the solution (so far the comments are pretty positive):
Another option is http://www.un4seen.com/bass.html (beware: commercial) - it does all you asked for, is free for use in non-commercial applications and there is a python wrapper (called pybass)...
回答2:
Have you considered Python Audio Tools? It has the ability to load an MP3 and play it using the Player
class. The Player
class initializer accepts an AudioOutput object, which lets you specify the number of playback channels.
The project seems well supported with the last git commit on October 30th of 2011 (just under two weeks prior to your posting). It's also been around for a while, so it doesn't appear to be a fly-by-night library.
回答3:
Gstreamer's Python bindings.
Here's a very simple music player:
import gobject
import gst
pipeline = gst.parse_launch('filesrc location="stereo.mp3" ! mad ! audioconvert ! audio/x-raw-int,channels=1 ! autoaudiosink')
pipeline.set_state(gst.STATE_PLAYING)
gobject.threads_init()
gobject.MainLoop().run()
I really suggest you look into Gstreamer as it has become a de-facto multimedia solution for most of the open source platforms and supports a wide variety of audio files. Sample apps using it: Rhythmbox, Banshee, Totem, etc...
回答4:
While this is not even close to a complete answer, to turn a multichanneled audio wav file into a mono one, you simply get the average of all the channels. In the case of stereo you would have:
mono[i]=(left[i]+right[i])/2
for each sample i
.
Hope it helps!
来源:https://stackoverflow.com/questions/8064784/mono-playback-of-mp3s-in-python-or-c