Making .mp3 files from .wav files

I have a love-hate relationship with iTunes.

For many reasons I don’t use it to manage my music. (like crashing and taking my library with it, like making it too hard to change the .mp3 quality on the fly, like being a bottleneck for “i”Devices, like not recognising Linux, etc)

I keep my music on an external hard-drive in .wav format.

When I want it on one of my other devices, I use the following applescript to produce .mp3’s from the selected .wavs:

-------8<--------------------------------------------------------------

-- Use this as you like, but at your own risk - it comes with no warranty for anything at all.

-- Select (multiple) .wav files in a folder and convert them to .mp3 files

-- uses lame from here: http://www.thalictrum.com/index.php?pageid=6&artid=6 (10.6 & up)

-- Get the wave files (to Do: make it a droplet!)
set WavFiles to choose file with prompt "Choose the .wav files to convert" default location "/Volumes/MYBOOK/Music/" with multiple selections allowed

try
-- because we use a shell script, work with POSIX paths (and quote them!)
repeat with aFile in WavFiles
set theFile to the POSIX path of aFile
-- Uncomment next line for info on files for debugging
--set infofile to info for theFile
do shell script "/usr/local/bin/lame --quiet --preset medium " & quoted form of theFile
end repeat

on error eMessage number eNumber
display dialog ("Error number was " & eNumber as string) & ": " & eMessage
return
end try

try

-- because lame spits out the original file with a .mp3 extension
-- we end up with .wav.mp3 files. This try block fixes that...
repeat with bFile in WavFiles
set origfile to the POSIX path of bFile & ".mp3" as string
set t1File to the POSIX path of bFile as string
set t2File to (text 1 thru ((count t1File) - 4) of t1File) as string
set destfile to t2File & ".mp3" as string
do shell script "mv " & quoted form of origfile & " " & quoted form of destfile
end repeat
display dialog " .mp3's created " buttons {"OK"} with icon note
on error eMessage number eNumber
display dialog ("Error number was " & eNumber as string) & ": " & eMessage
end try

-------8<--------------------------------------------------------------

The place I got
lame from is in the comments in the script. It does all the heavy lifting.

There really isn’t anything tricky about this code, except that lame just tacks an .mp3 extension on to the original file, resulting in a file “filename.wav.mp3”, which I find ungainly. That’s the reason for the second “repeat” loop - it finds all those files we just made with the double extensions and makes them into “filename.mp3” - much neater!

To use this applescript on your mac, get lame and install it. Copy the code from above, paste it into the AppleScript Editor (using “Paste and Match style”), change (or remove) the “default location” to your default for your .wav files, compile, test and store in your applescript folder.

For me, this answers the need for .mp3 files for my Windows and Linux computers, and my other “i”Devices that live with me.

Hope you find it useful.

Comments