Convert a wav file to mp3 with FFmpeg, pydub, and three lines of Python

Ten minutes ago I played a song I had not heard before and said, that was a good song! I should send it to Sam. But it's in WAV format so it's really big.

Wouldn't it be nice if Python could convert it to mp3 to make it smaller?

Ten minutes later it was done. Amazing.

Here are the easy steps to follow if you would like to try it.

1. Search the internet for 'python convert wav mp3'.

2. Download FFmpeg and add it to your system path:

http://adaptivesamples.com/how-to-install-ffmpeg-on-windows/

3. 'pip install pydub', then copy some sample code from here and make slight adjustments to match your file paths and song file name:

https://github.com/jiaaro/pydub

4. Run the script:

from pydub import AudioSegment
song = AudioSegment.from_wav("G:/Music/Rock/The I Don't Cares/Wild Stab/Sorry for Tomorrow Night.wav")
song.export("Sorry for Tomorrow Night.mp3", format="mp3")

5. Email the mp3 file to Sam.

And done in less than ten minutes.

Thank you, programmers and documenters of the internet.

The Song: Sorry for Tomorrow Night (Westerberg) - The I Don't Cares

Comments

Popular posts from this blog

Date Dimension Table Definition

In Appreciation of Procedural Programming

Stop Flickering Pointer in Vista's Windows Explorer