Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert a WAV from stereo to mono in Python?

Tags:

I don't want to use any other apps (like sox) - I want to do this in pure Python. Installing needed Python libs is fine.

like image 585
Matt Avatar asked Feb 25 '11 17:02

Matt


People also ask

How do I turn my stereo into mono?

Select the Start button, then select Settings > Ease of Access > Audio, and then switch on the toggle under Turn on mono audio.

What is Pydub in Python?

pydub is a Python library to work with only . wav files. By using this library we can play, split, merge, edit our . wav audio files.


1 Answers

I maintain an open source library, pydub, which make this pretty simple

from pydub import AudioSegment sound = AudioSegment.from_wav("/path/to/file.wav") sound = sound.set_channels(1) sound.export("/output/path.wav", format="wav") 

One caveat: it uses ffmpeg to handle audio format conversions, but if you only use wav it can be pure python.

like image 75
Jiaaro Avatar answered Sep 28 '22 07:09

Jiaaro