Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'd like to convert many WAV files to MP3 files using LAME and Automator. I need a script that I could right click a folder and convert all the WAV files inside the folder to MP3 files. I've been able to find a script to convert single file but I don't know how to modify it so I could convert many files with a single click.

I've been using script which I found here for single files. Here is a similar question but instead of using "Run Applescript" it uses "Run Shell Script". I've tried to replace LAME parameters between "do" and "done" but haven't succeeded to convert anything.

So, how could I convert folder full of WAV files to MP3 files? For me it doesn't matter is it done by using Applescript or Shell Script in Automator if both ways are possible.

share|improve this question
    
If you don't insist on using LAME, Doug's Applescripts for iTunes is a useful source. dougscripts.com/itunes –  Wheat Williams Aug 22 '11 at 22:11
    
This goes .flac --> .mp3 so adds a step, but the idea is the same. It could be easily modified to deal with .wav instead of .flac. It's done in the terminal. I use it daily. –  boehj Aug 23 '11 at 0:08
    
I have checked those Applescripts for iTunes and they are great but I want to use the latest LAME to convert my WAV files. Anyway, thanks for your help! –  nqw1 Aug 24 '11 at 6:28
    
I know this doesn't answer your question, but couldn't you use Switch? –  daviesgeek Sep 20 '11 at 16:12
    
@daviesgeek — I do not recommend that using that app. –  l'L'l Sep 22 '11 at 19:09
show 2 more comments

3 Answers

up vote 3 down vote accepted

Automator 'hangs' when attempting to use LAME encoder unfortunately. It's also not efficient or advisable to try and use a multi-threaded process as an Automator Service. For tasks such as this it's best to either run a simple script or use an alternate method.

The script below will encode a 20Mb .wav to .mp3 in 3 seconds! (at the highest quality settings)

file="$1"

find . -name '*.wav' -maxdepth 1 -exec /usr/local/bin/lame -V 0 -q 0 '{}' \;

for file in *.mp3
do
  mv "$file" "${file/wav./}"
done

To install, download, then open terminal:

sudo install encode-mp3 /usr/local/bin

To use, navigate into a desired conversion folder and type:

encode-mp3

This will encode your .wav files to .mp3

Convert .wav to .mp3 | LAME Encoder Shell Script [md5: 72d4e24f14ea9139136900f2c4281a7f]


[original]

I just wrote a one-liner that will do this for you in Terminal, just cd to the directory of files you want to convert and enter:

find ./ -name "*.wav" -execdir lame -V 3 -q 0 {} \;
share|improve this answer
    
Thank you for this! It worked perfectly. However, I don't want to open Terminal every time I convert files. Is it possible to use this in Automator? I would like to just right click a folder to convert files inside it. I tried to use it as a Shell Script but I didn't get it working. –  nqw1 Aug 24 '11 at 6:23
    
Sure thing! It looks like you got it working w/automator since the last time I was here. I'm glad my one liner helped in the outcome of eventually accomplishing what you wanted; Hopefully it can help someone else as well. –  l'L'l Sep 16 '11 at 2:17
    
I still haven't been able to get it working on Automator. I have tried many things which can be read from the other answer. If you have more suggestions, feel free to help :) –  nqw1 Sep 19 '11 at 5:30
    
I created an Automator version for you. I have it setup so that Control + Mouse Clicking a FOLDER will bring up Services > Convert .wav to .mp3, which then converts the entire folder. Let me know if my workflow solves your problem. –  l'L'l Sep 20 '11 at 6:55
    
Thank you a lot for your help but I have the same problem as in the other answer. I have folder which contains 3 WAV files named 01.wav, 02.wav and 03.wav. I use the script for the folder and it starts to convert the files. It creates only one unfinished MP3 file which length is around 30 seconds and the service keeps running on background. After this, nothing happens. I manually have to shut the service down. I downloaded your script and didn't make any adjustments. I also tried to right click files and use the script but it didn't work. Any idea where could be the problem? :) –  nqw1 Sep 20 '11 at 12:57
show 3 more comments

You can use the following in Automator's "Run Shell Script" action (make sure to change "Pass input" to "as arguments"):

find "$1" -name "*.wav" -execdir /usr/local/bin/lame -V 0 -q 0 {} \;

This will find all .wav files in the selected folder, including sub-folders (and skip over any non-wav files). If you don't want it to look into sub-folders, you can change it to this:

find "$1" -name "*.wav" -maxdepth 1 -execdir /usr/local/bin/lame -V 0 -q 0 {} \;

Of course, you would change -V 0 -q 0 to whatever lame options you prefer.

If you want to be notified when it's done, you can add a say command, use a "Show Growl Notification" action (if you have Growl installed), or use a beep command in a "Run AppleScript" action.

Below is a screenshot of what my workflow looks like with the extra say command and the Growl notification. Also notice I changed the "Service receives selected" option at the top to "folders" (it will be "text" by default).

Lame WAV to MP3 Batch Conversion

share|improve this answer
    
Thank you for your help! I wasn't able to get it working though. I guess I should but the line between "do" and "done" in that Shell Script, right? All I get is one 21 second MP3 file and infinite loop or something. I guess I'm doing something wrong :) I remembered to change "pass input" to "as arguments". –  nqw1 Aug 24 '11 at 6:27
    
@nqw1 With the find command, you don't need to use the for, do, or done commands at all. Those commands form a loop statement to process each file in the folder. The find command yields similar results, but it will only run lame on files with the .wav extension. I'll edit the answer & include a screenshot from Automator. –  joelseph Aug 24 '11 at 19:48
    
Thank you for your kind help! This is getting weird because I have everything exactly as in your screenshot but still it's creating only one unfinished ~20 second MP3 file and the service stays in infinite loop or something. I have to manually shut it down and then the Growl message appears. I even checked that folder path /usr/local/bin and there is lame file. Do you have any idea what could be the problem? –  nqw1 Aug 25 '11 at 6:27
    
If you try ioi's answer in the same folder, does it get stuck on the same file? If so, that file may be corrupt. Another possibility may be that you may need to just give it more time to complete. On my 2.5 GHz Core 2 Duo with 4 GB RAM, it takes about 15 seconds for a 5 minute song. While I don't think it should make a difference, it may be worth mentioning that I've only tested this Automator workflow with lame 3.98.4 installed in Lion. –  joelseph Aug 25 '11 at 15:55
    
ioi's answer works perfectly. I can convert the same WAV file(s) in ~10 seconds. I also use 3.98.4 LAME version but I have OS X 10.6.8 Snow Leopard. I guess that shouldn't make the difference? I guess the problem must be somewhere in Automator if I'm able to use LAME in Terminal.. My Automator version is 2.1.1 (247.1). –  nqw1 Aug 26 '11 at 5:47
show 3 more comments

The thread is a bit updated, but for those who may find it useful,

I used Automator setup described here, and was able to avoid getting it stuck with -S option of lame, so my "Run Shell Script" command looks like:

    find "$1" -name "*.wav" -maxdepth 1 -execdir /usr/bin/lame -b 160 -q 0 -S {} \;

(besides, my lame exec is in another place)

The -S option turns off Lames progress report

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.