Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a .wav file to a .caf file for use in iOS

I don't know squat about audio or the Terminal. I've use this Terminal command to convert a wav file for use in iOS:

afconvert -v -f 'caff' -d LEI16 -s 1 /users/myUserName/Desktop/hibeep.wav /users/myUserName/Desktop/hibeep.caf

After adding the file to my project, nothing happens when I execute:

NSURL * softURL = [[NSBundle mainBundle] URLForResource: @"hibeep" withExtension: @"caf"];
CFURLRef softSoundURL = (__bridge CFURLRef) softURL;
AudioServicesCreateSystemSoundID(softSoundURL, &_beepSound);
AudioServicesPlaySystemSound (_beepSound);

Yet, when I click on hibeep.caf in the Project Navigator, the sound will play fine.

I have tried this in both the simulator and on an iPad.

Any suggestions?

Thanks

like image 601
Carl Carlson Avatar asked Dec 04 '22 04:12

Carl Carlson


2 Answers

TL;DR;

afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v

Long version: I know this is old, but this thread has solved my problem, so here's solution to the problem in the question.

CAF is only a container and you are using the wrong codec for the data held in the container. Quote from apple doc:

Custom alert sounds are played by the iOS system-sound facility, so they must be in one of the following audio data formats:

Linear PCM MA4 (IMA/ADPCM) µLaw aLaw

Here's the proper terminal command when converting WAV to CAF (MA4)

afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v
like image 198
Raimundas Sakalauskas Avatar answered Dec 21 '22 13:12

Raimundas Sakalauskas


Try to select your audio file and check if the target is selected xcode

like image 30
3CC Avatar answered Dec 21 '22 14:12

3CC