3

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

Fábio Diniz
  • 10,077
  • 3
  • 38
  • 45

4 Answers4

4

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

Yahia
  • 69,653
  • 9
  • 115
  • 144
  • Pyaudio will only manipulate streams of data (that id have to read with another library like pymedia), is it possible to add stuff like seeking to it in a simple way? I still have to check if ffmpeg can be used and the other 2 solutions are not suited (one in C# and the other is too low-level) – Fábio Diniz Nov 13 '11 at 23:28
  • @FabioDiniz link 3 was just to show how the API from link 4 can be used... I added another option which does all you asked for but this one is commercial - not sure that is ok for you – Yahia Nov 14 '11 at 05:05
  • OH WOW. Bass is incredible, it really does all I've asked, at home I'll conduct more tests but everything is working the way I wanted so far. – Fábio Diniz Nov 14 '11 at 12:08
  • @FabioDiniz glad to read that... one addition: the license states that it is free for use in non-commercial software :-) – Yahia Nov 14 '11 at 12:13
  • Yeah, and as im coding a non-commercial application it fits perfectly. Im also using a python wrapper called pybass, and it is really incredible. I can even turn to mono WITHOUT restarting the stream, which is really impressive for such a high level library – Fábio Diniz Nov 14 '11 at 12:52
1

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.

Nathan
  • 4,777
  • 1
  • 28
  • 35
  • After a bit of reasearch i havent found a way (or binaries) to get it working on Windows, and i need it to be windows-compatible – Fábio Diniz Nov 12 '11 at 20:08
1

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

plaes
  • 31,788
  • 11
  • 91
  • 89
  • Id really like to use gstreamer, but i have this issue posted on this [question](http://stackoverflow.com/questions/6907473/cannot-import-gst-in-python), and the solution posted does not work for me – Fábio Diniz Nov 12 '11 at 19:38
  • Oh yes, the joys of Windows and its lack of package management :S – plaes Nov 12 '11 at 20:45
  • =( Im downgrading to python 2.6 to see if i get gst work, but id really prefer a solution in which i could use python 2.7 – Fábio Diniz Nov 12 '11 at 20:47
  • I got it to work but the windows support is horrible (im using Ossbuild), theres a lag to play/pause (and a hiccup) and lag to change the volume, but (sadly) the mono/stereo feature works quite well – Fábio Diniz Nov 13 '11 at 09:02
  • @FabioDiniz How are you sending the play/pause messages? – plaes Nov 13 '11 at 14:14
  • by using set_state(gst.STATE_PLAYING) and set_state(gst.STATE_PAUSE). It seems a problem similar to [this](http://gstreamer-devel.966125.n4.nabble.com/PLAY-gt-PAUSE-gt-PLAY-hickup-td1592437.html). Maybe ossbuild is not ready yet, I`ve tried Banshee for windows and it is as sluggish as my application. – Fábio Diniz Nov 13 '11 at 17:41
0

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!

polvoazul
  • 2,208
  • 2
  • 19
  • 25