问题
I am working on a project that requires me to send raw headerless ulaw or linear pcm data to a server.
I am using the AVAudioRecorder and I can save out audio files to the phone quite easily, but the problem is that it no matter what I try and do, they get wrapped in a caf file or stamped with some kind of header.
It's my understanding that a caf file is just a wrapper file for raw audio data and that this audio data can be in various formats including linear pcm and ulaw.
So my questions are, how can I generate a raw audio file without the caf wrapper to begin with (ie just the headerless raw audio stuffed into a file) or if I record a caf that contains the raw Ulaw or linear pcm audio data, how can I easily go in and extract just the raw audio data from the caf file and leave everything else behind.
回答1:
If you use the Audio Queue API for recording, instead of AVAudioRecorder, you will have access to raw PCM sample buffers, and can write those out to a flat file for later sending to your server.
回答2:
If the audio data in the CAF is already in the format you need it in, I'd use the AudioFile API to grab the caf file's audio data and write them to a headerless/RAW file before uploading to my server.
If you need to convert the CAF's data, use the ExtAudioFile API instead. Either way, pretty straightforward.
http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/AudioFileConvertRef/Reference/reference.html
http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/ExtendedAudioFileServicesReference/Reference/reference.html
来源:https://stackoverflow.com/questions/3982596/how-can-i-access-extract-rawheadless-audio-data-from-a-caf-file-on-iphone