Python convert wav to mp3

xxjjnn picture xxjjnn · Apr 23, 2012 · Viewed 24.8k times · Source

I've looked at pymedia (discontinued), pyglet(great but no converter in there) and audiotools(command line cd ripping), and none seem suitable.

In Python 2.7 , how do you do

convert(wavFileLocation, 'mp3')

If there is no python way, how would you do it in a manner which python can invoke? (e.g. Call a Cross platform command line tool... if exists return (name, pythonCodeForInvocation) )

Answer

Jiaaro picture Jiaaro · Sep 12, 2012

I wrote a python library, pydub, that essentially does what Corey's Answer suggests, though it uses ffmpeg in to do the conversions in order to support more formats.

from pydub import AudioSegment

AudioSegment.from_wav("/input/file.wav").export("/output/file.mp3", format="mp3")