将多个.wav转换为.caf

FBr*_*t87 9 iphone audio xcode cocos2d-iphone

我正在制作iPhone应用程序,.wav我需要转换为大量文件.caf

我可以将它用于每个文件:

afconvert -f caff -d LEI8@22050 walking.wav walking.caf
Run Code Online (Sandbox Code Playgroud)

但这需要很长时间,所以我试图转换所有文件:

for i in *.wav; do afconvert -f -caff -d LEI16@44100 -c 1 $i ${i%.wav}.caf; done
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

Error: ExtAudioFileCreateWithURL failed ('typ?')
Run Code Online (Sandbox Code Playgroud)

编辑:由于上面显示的for循环中的拼写错误,实际上会发生错误.应该caff不是-caff.那么正确的代码片段就是.

for i in *.wav; do afconvert -f caff -d LEI16@44100 -c 1 $i ${i%.wav}.caf; done
Run Code Online (Sandbox Code Playgroud)

可能存在其他问题,并且接受的答案是有效的,只是想帮助解决问题./编辑

小智 16

这是我一直在使用的脚本,稍微从其他来源修改,这值得所有信用:

##
## 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 afconvert_wavtocaf.sh'
## Any comments to 'support@ezone.com'
##

for f in *.wav; do
if  [ "$f" != "afconvert_wavtocaf.sh" ]
then
 afconvert -f caff -d ima4 $f
 echo "$f converted"
fi
done
Run Code Online (Sandbox Code Playgroud)

将其保存在名为"afconvert_wavtocaf.sh"的文件中.看看是否有诀窍.