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

后端 未结 2 1034
孤街浪徒
孤街浪徒 2021-02-02 12:42

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.

2条回答
  •  Happy的楠姐
    2021-02-02 13:14

    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.

提交回复
热议问题