4

Is there a way in python to play two different mono mp3 files through the left and right channels?

I have two mp3 files and I want to play one through the left speaker and the other mp3 through the right speaker, programatically in python. Any solution is OK. If it is a cross-platform solution, then great. Does any one have any suggestions?

Vimal
  • 61
  • 5

1 Answers1

2

For a simple solution, download and try the audiere module. This will open the first available audio device:

import audiere
ds = audiere.open_device()
os = ds.open_array(input_array, sampling_frequency)
os.play()

Where your input_array should be 2-dim numpy array of floats, you could e.g. decompress your input mp3s into left and right 1-dim arrays and then use input_array = np.c_[left, right]. Since the data is a raw array you need to specify the sampling_frequency of your input. If they're different lengths you'll need to pad one or the other with zeros.

wim
  • 338,267
  • 99
  • 616
  • 750
  • Is it a good idea to load the full mp3 file (which can be 4-5mb in size) to an array? Is it possible to load the left and right channels with separate files if we use gstreamer or any other standard python modules? – Vimal Sep 12 '11 at 12:41
  • I'm sure it is possible, but it would probably be a whack more effort than this quick and dirty solution. Loading the raw data to an array shouldn't be too much of a problem on most machines these days (it would be 100-200MB memory). Have you considered just writing a shell script to convert your files to mono and then write a new stereo file from the separate channels? – wim Sep 12 '11 at 12:59