0

I wrote this code with pydub. I want to make to different variables with the same song. One song would just play in the left ear and one song would just play in the right ear.

from pydub import AudioSegment


src = "or_test.mp3"
dst1 = "mono_left.mp3"
dst2 = "mono_right.mp3"    # enter code here

sound1 = AudioSegment.from_mp3(src)
sound2 = AudioSegment.from_mp3(src)
    
mono_audios1 = sound1.split_to_mono()
mono_audios2 = sound2.split_to_mono()

mono_left = mono_audios1[1].export(dst1, format="mp3")
mono_right = mono_audios1[0].export(dst2, format="mp3")

When I run mono_right or mono_left the sound plays from both ears, but I don't want it like that.

How do I correct this?

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41

1 Answers1

0

sound2 and mono_audios2 are not needed. mono_audios indexes 0 and 1 - left and right - are inverted. In AudioSegment.from_mp3 you also need to specify a format.

from pydub import AudioSegment

src = "or_test.mp3"
dst1 = "mono_left.mp3"
dst2 = "mono_right.mp3"

stereo_audio = AudioSegment.from_file(src, format="mp3")
mono_audios = stereo_audio.split_to_mono()
 
mono_left = mono_audios[0].export(dst1, format="mp3")
mono_right = mono_audios[1].export(dst2, format="mp3")

If this doesn't work, then it's the audio player.

Attersson
  • 4,755
  • 1
  • 15
  • 29