Open In App

Splitting stereo audio to mono with PyDub

Last Updated : 16 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Splitting a stereo audio file into multiple mono audio files is very useful if you are trying to process or transcribe the stereo audio files. This is because stereo audio has 2 audio sources on different channels which makes it very hard to process the file. Splitting the stereo audio file into mono audio files makes this job easier.

For this article, we will be using the Pydub python module, which is very useful for working with audio files and modifying them. For more information read this Pydub article.

Pydub installation using pip:

pip install pydub

What are Stereo and Mono Sounds?

Stereo Audio: It is a 2 channel audio, which means that two or more sound sources are localized to the left and right side while listening. This is most commonly used in Audio or Video streaming services where sounds of different instruments can be heard from specific sides of the headphones.

Mono Audio: It is single-channel audio, which means that all sound sources are heard through one channel only. This means that you will hear the same sound on the left and right sides of the headphones. This is the format in which the phone microphone records audio.

Folder Structure

In a folder named pydub, I have my python code file named main.py having the below code, and a test audio file named stereo_audio.wav.

Initial Folder Structure

Explanation

  1. Import AudioSegment from pydub
  2. Open an audio file as an AudioSegment instance using AudioSegment.from_file() method.
  3. Call the split_to_mono method on the file which splits the stereo audio file into left and right channel audio and returns a list where the left channel AudioSegment object is at 0 index and the right channel one is at 1 index.
  4. Export/Save both the mono audio files in the desired format.

Note: Remember to change the file paths according to your system.

Implementation:

Python3




# Python3 program to illustrate
# splitting stereo audio to mono
# using pydub
  
# Import AudioSegment from pydub
from pydub import AudioSegment
  
# Open the stereo audio file as
# an AudioSegment instance
stereo_audio = AudioSegment.from_file(
    "C:\\Users\\NEERAJ RANA\\Desktop\\GFG_Articles\\pydub\\stereo_audio.wav",
    format="wav")
  
# Calling the split_to_mono method
# on the stereo audio file
mono_audios = stereo_audio.split_to_mono()
  
# Exporting/Saving the two mono
# audio files present at index 0(left)
# and index 1(right) of list returned
# by split_to_mono method
mono_left = mono_audios[0].export(
    "C:\\Users\\NEERAJ RANA\\Desktop\\GFG_Articles\\pydub\\mono_left.wav",
    format="wav")
mono_right = mono_audios[1].export(
    "C:\\Users\\NEERAJ RANA\\Desktop\\GFG_Articles\\pydub\\mono_right.wav",
    format="wav")


Output:

Folder Structure After Running Code

Output Video:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads