convert audio file .m4a

Hi,

I would like to convert an audio file with format .m4a into mp3 or WAV or anything with an AppleScript.
Can this be done?

.Tobias

Hi.

You could check out “afconvert”, a command-line executable that’s built into Mac OS. I use the following to convert sound files to raw AAC for use in my car:

set infile to POSIX path of (choose file of type {"public.aifc-audio", "com.apple.m4a-audio"})

(* afconvert
Specify the output file with the -o option. if the output file's not specified, it's created in the same folder as the original with an appropriate name extension.
-f adts specifies the appropriate output file format for raw AAC data.
-d aac specifies raw AAC data. (Maybe this should be -d 'aac '.)
-s 3 specifies the use of a Variable Bit Rate strategy.
*)
do shell script ("/usr/bin/afconvert " & quoted form of infile & " -f adts -d aac -s 3")

Unfortunately, the ‘man’ page isn’t very informative, but the -h and -hf options return information about options and formats respectively which should help you get what you want. It looks as if the line for .mp3 should be something like:

do shell script ("/usr/bin/afconvert " & quoted form of infile & " -f MPG3 -d '.mp3'")

But you should read up about the formats which interest you first to see what options are appropriate.

If metadata is important to you, use iTunes

tell application "iTunes"
	set current encoder to encoder "MP3 Encoder"
-- no WAV
        convert theFile
end tell

else you can use do shell script "afconvert …

Start by typing afconvert -h in the terminal.

I’m trying this:

do shell script ("/usr/bin/afconvert -f wav -d 'aac ' -c 1 /Volumes/HD2/test.m4a /Volumes/HD2/test.wav")

But, it returns: “Error: ExtAudioFileCreateWithURL failed (‘typ?’)”"

Anyone?

If you’re specifying the path to the output file, it should be preceded by -o. But if you want the file to appear in the same folder as the original, and with the appropriate extension, you don’t need to specify the destination at all.

According to the information returned by “afconvert -hf”, the -f value for .wav files is ‘WAVE’ and the -d value should be one of the following: UI8, LEI16, LEI24, LEI32, LEF32, LEF64, ‘ulaw’, or ‘alaw’. I haven’t looked into .wav files, so I don’t know which alternative to suggest. These data refer to the file you want to create. The format of the original file is detected automatically.

do shell script ("/usr/bin/afconvert -f 'WAVE' -d 'aac ' -c 1 -o /Volumes/HD2/test.m4a /Volumes/HD2/test.wav")

returns

Error: ExtAudioFileCreateWithURL failed (‘fmt?’)

do shell script ("/usr/bin/afconvert /Volumes/HD2/test.m4a -o /Volumes/HD2/test.wav -f 'WAVE' -d 'ulaw' -c 1")

Or:

do shell script ("/usr/bin/afconvert /Volumes/HD2/test.m4a -f 'WAVE' -d 'ulaw' -c 1")

As I wrote in my previous post, the data format for a .wav file should be UI8, LEI16, LEI24, LEI32, LEF32, LEF64, ‘ulaw’ , or ‘alaw’. I’ve used ‘ulaw’ in the examples above, but I don’t know which is right for you. It’s definitely not 'aac '.

Both works just fine - thanks a lot!

So now I have:

do shell script ("/usr/bin/afconvert /Volumes/HD2/test.m4a -o /Volumes/HD2/test.wav -f 'WAVE' -d 'ulaw' -c 1")

What if I would like to convert from .m4a to .mp3 (LAME)?

This is what I’m using to do conversion from WAV to .mp3

do shell script "/usr/local/bin/lame -V 3 /Volumes/HD2/1.wav /Volumes/HD2/1.mp3"

Is there a way to combine the two shell scripts to be able to convert from .m4a to .mp3?