How To: Convert a Directory of MP3s to WAVs in Linux
r3dux | November 10, 2009I went to burn a couple of audio CDs for the boy today, and bod-frickn-dammit if Brasero / GnomeBaker and K3B didn’t all threw their hands in the air in dismay that I might actually have the nerve to want to convert mp3s to CD-audio on the fly. Very poor.
So, as wav files come in less flavours than mp3s and tend to work first time, I knocked up a quick script to convert a directory of mp3s to .wav files using mpg123, it even handles spaces correctly after I’d given it a stern talking to… Anyways:
#/bin/bash gotmpg123=$(which mpg123) # If there's no copy of mpg123 we're not going to be doing any converting. Abort! if [ "$gotmpg123" = "" ]; then echo "No copy of mpg123 found on system! Try running: sudo apt-get install mpg123" exit 0 fi # Otherwise, if we're all set, make a directory to dump our wav files into mkdir WAV # For each file in the current directory that ends with .mp3, convert it to .wav and place in our new WAV folder for file in ./*.mp3 do mpg123 -w ./WAV/"${file}".wav "$file" done
To use the script:
- Copy and paste the above code into a new text file called mp32wav or something
- Make it executable with chmod +x mp32wav, then
- Copy it to /usr/bin for easy access with sudo cp mp32wav /usr/bin/
With that all done you can just go into a folder of mp3s in the terminal and fire it off. It’ll create a folder called WAV inside whatever directory you’re in and stick the converted wav files there with the original filename but with .wav tacked on the end.
Cheers!








