Objective-c – How to record and play back sound on the iPhone

core-audioiphoneobjective c

In my app I've got certain buttons which use the following code:

SystemSoundID beep;

CFStringRef beepPath = (CFStringRef) [NSString stringWithFormat: @"%@/SoundFile.aif", [[NSBundle mainBundle] bundlePath]];
AudioServicesCreateSystemSoundID (CFURLCreateWithFileSystemPath (NULL, beepPath, kCFURLPOSIXPathStyle, false), &beep);
CFRelease(beepPath);

AudioServicesPlaySystemSound (beep);

I would like the user to start recording and be able to record any sounds made by the app and then have the ability to play the recorded sound after a certain time limit, or have a stop recording button and then a 'Play' button to play the recorded clip.

Any ideas on how I can implement this?

Best Answer

The obvious solution would be to save the sequence of user actions in an NSArray, and play them back to recreate the sounds. I'm not sure that you can record the output sound channel into another file, if that's what you're trying to do.