Vimal
Vimal

Reputation: 61

Play audio through muliple channels with python

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?

Upvotes: 4

Views: 803

Answers (1)

wim
wim

Reputation: 363486

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.

Upvotes: 2

Related Questions