views:

1327

answers:

4

I have a directory with about 50 wav files that I need to convert to caf, because AudioServicesCreateSystemSoundID() returns an error for some of them (but not all).

Here's an example of the command I've used successfully for a single file:

afconvert -f caff -d LEI16@44100 -c 1 whistle.wav whistle.caf

How do I do this quickly - not one-by-one for each file?

+4  A: 

Use the %~ni syntax.

for %i in (*.wav) do afconvert -f caff -d LEI16@44100 -c 1 %i %~ni.caf
lavinio
What does %~ni do?
mahboudz
I see, it removes the last filename extension. Cool!
mahboudz
I tried to use that command but it gave mi this error:-bash: syntax error near unexpected token `('
José Joel.
That's because this particular `for` command is for the Windows command processor, not for the bash *nix shell.
lavinio
+3  A: 

Similar approach for bash:

for i in *.aif; do afconvert -f caff -d LEI16@44100 -c 1 ${i} \basename ${i} .aif\.caf; done

Randall
+1  A: 

Elliot,

How did you figure out that you needed to use the -d LEI16@44100 setting in order to convert the files? I only discovered the afconvert command today, and don't know how to use all the various settings.

Duncan C

Duncan C
I think it was from a previous Stack Overflow question.
Elliot
+1  A: 

found this:

##
## Shell script to batch convert all files in a directory to caf sound format for iPhone
## Place this shell script a directory with sound files and run it: 'sh converttocaf.sh'
## Any comments to '[email protected]'
##

for f in *; do
    if  [ "$f" != "converttocaf.sh" ]
    then
        /usr/bin/afconvert -f caff -d LEI16 $f
        echo "$f converted"
    fi
done

Customize the aconvert options then save it as a text file called 'converttocaf.sh', place it in the directory of files you want to convert and run it from Terminal.

Ward