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,
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?