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

自古美人都是妖i 提交于 2019-12-03 17:25:09

问题


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.


回答1:


If the WAV file is PCM-encoded then you can use wave. Open the source and destination files, read samples, average the channels, and write them out.




回答2:


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.



来源:https://stackoverflow.com/questions/5120555/how-can-i-convert-a-wav-from-stereo-to-mono-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!