Go to ...

Techpository

A Better Technical Repository

RSS Feed

Linux: Batch convert mp3 to wav


Install mpg123
sudo apt-get install mpg123

Make certain all of your mp3 audio files are in the same directory.

Put the following code into a file:
vi mp3towav.sh

###Start of script###
for i in *.mp3 ; do
echo $i
b=`basename $i .mp3`
mpg123 -w $b.wav input $i
done
###End of script###

Put the conversion script into the same directory as your mp3s
chmod +x mp3towav.sh

Simply run ./mp3towav.sh

 

* Note – If there are spaces in your file names you will get errors and the conversion process will fail.
The easiest way to fix this is to replace the spaces with another character like a dash

Here is a script to remove the spaces in a file and replace them with dashes:
vi spacetodashconvert.sh

###Start of script###
#!/bin/bash

ls | while read -r FILE
do
mv -v “$FILE” `echo $FILE | tr ‘ ‘ ‘-‘ `
done
###End of script###

Run this in the same directory that contains your mp3 files, then re-run the mp3towav script