Splitting stereo audio to mono with PyDub
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.
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.
- Import AudioSegment from pydub
- Open an audio file as an AudioSegment instance using AudioSegment.from_file() method.
- 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.
- Export/Save both the mono audio files in the desired format.
Note: Remember to change the file paths according to your system.