Princess Cornflakes

Too trashy to print on a cereal box

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

with one comment


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.

Advertisements

Written by nattie

May 29, 2010 at 2:01 pm

Posted in Uncategorized

One Response

Subscribe to comments with RSS.

  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 :).

    Solomon Rutzky

    May 30, 2010 at 12:25 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: