Best bet is to write WAV files with ulaw or alaw compression (the mFormatId
of your AudioStreamBasicDescription
would be kAudioFormatULaw
or kAudioFormatALaw
. Test to see which one gives you the smallest file sizes for your application.
Here s some code to set up an ExtAudioFile instance to write ulaw:
NSArray * docs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * docDir = [docs objectAtIndex:0];
NSURL * outFile = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:@"OutFile.wav"]];
AudioStreamBasicDescription asbd;
bzero(&asbd, sizeof(asbd));
asbd.mSampleRate = 11025; // or whatever
asbd.mFramesPerPacket = 1;
asbd.mChannelsPerFrame = 1;
asbd.mFormatID = kAudioFormatULaw; //or kAudioFormatALaw
ExtAudioFileRef theFile;
err = ExtAudioFileCreateWithURL((CFURLRef)outFile,
kAudioFileWAVEType,
&asbd,
0,
kAudioFileFlags_EraseFile,
&theFile);
Hope that helps.
--- ADDED ---
Here are modifications to the SpeakHere sample code to get ulaw compression:
SpeakHereController.mm:116
recordFilePath = (CFStringRef)[NSTemporaryDirectory() stringByAppendingPathComponent: @"recordedFile.wav"];
SpeakHereController.mm:158
recorder->startRecord(CFSTR("recordedFile.wav"));
AQRecorder.mm:192
SetupAudioFormat(kAudioFormatULaw);
AQRecorder.mm:215
XThrowIfError(AudioFileCreateWithURL(url, kAudioFileWAVEType, &mRecordFormat, kAudioFileFlags_EraseFile,
&mRecordFile), "AudioFileCreateWithURL failed");