use lame to convert directory of .wav files to .mp3

If you use Ubuntu (or any other distribution of Linux) it can be surprisingly hard to convert a whole directory of .wav files to .mp3.

There is a utility called “lame” which works pretty well converting a single .wav file, i.e.:

lame filename

but who wants to sit there typing “lame” over and over again?

Oh sure, you could convert all the files using “find -exec” like this:

find . -name "*wav" -exec lame {} \;

But then you will find out how “lame” lame truly is! It leaves the “.wav” file endings, attaches a “.mp3” to them and this:

White Line 11-10-76.wav

becomes this:

White Line 11-10-76.wav.mp3

So you’d have to go through each file individually and remove the “.wav” ending as well as the spaces in the filenames!

Here is a better way. Though not perfect, it works. Each of these commands will execute on all files in the directory, so you only have to run each command once.

1. remove the spaces from the filenames:
find -type f -exec rename 'y/\ /\_/' {} \;

2. and get rid of the .wav from filenames*:
for file in *.wav ; do mv $file `echo $file | sed 's/\(.*\).wav/\1/'` ; done

3. Now run lame on the batch
find . -type f -exec lame -b 224 {} \;

Enjoy your .mp3 files!

* Step 2 is a little weird. After this step you are going to end up with files that have no file endings, but lame seems to recognize these as “.wav” files.

0 thoughts on “use lame to convert directory of .wav files to .mp3”

  1. Can you maybe combine Steps 2 & 3 with something like:

    for file in *.wav ; do set newfile = `echo $file | sed ‘s/\(.*\).wav/\1/’` ; mv $file $newfile ; lame -b 224 $newfile ; done

    I have not tried this but I think it would work. And at that point, most likely can add Step 1 into the “do” loop as well :).

Leave a Reply

Your email address will not be published. Required fields are marked *