Mono Playback of Mp3s in Python OR C++

ぐ巨炮叔叔 提交于 2019-12-06 02:17:22

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:

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)...

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.

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

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!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!