Is there a recommended approach to safeguarding against audio recording losses via app crash?

AVAudioRecorder leaves a completely useless chunk of file if a crash happens while recording.

I need to be able to recover. I'm thinking of streaming the recording to disk. I know that is possible with AVAudioEngine but I also know that API is a headache that will lead to unexpected crashes unless you're lucky and the person who built it.

Does Apple have a recommended strategy for failsafe audio recordings? I'm thinking of chunking recordings using many instances of AVAudioRecorder and then stitching those chunks together.

Hello @bryan1anderson, thank you for your post. If you are streaming PCM audio data to disk, you should be able to recover the recorded fragment after a crash. You would likely benefit from using a lower-level API than AVAudioRecorder, though.

Stitching multiple AVAudioRecorder recordings might not work well if the stitching needs to be very precise, such as if you are recording music, for example. Precise stitching would be best accomplished with accurate start timestamps for each recorded fragment.

With AVAudioEngine, AVCaptureSession, Audio Toolbox, or Core Audio, you can access the underlying PCM audio data and associated timestamps, which is what you need in order to stream this data to disk.

The Using Voice Processing sample code project demonstrates how to record audio files using AVAudioEngine. In a nutshell, you install a tap on the engine's input node, then stream the received PCM buffers to disk. The project uses AVAudioFile for writing the buffers to disk, but that is not a requirement. You could write the data from the buffers to an OutputStream, for example.

Is there a recommended approach to safeguarding against audio recording losses via app crash?
 
 
Q