开发者

iPhone compressed audio formats that will play on Windows Media player

I have to record audio on an iPhone that will play back on Windows Media Player, using no non-standard codecs; that is, using no codecs that don't already ship with WMP. (Corporate requirement.) The audio has to go base-64 to a server, so I need to get the audio size as small as possible. Even at 8Kb recording frequency, AIFF files take ginormous amounts of space. I can't see开发者_StackOverflowm to find a compressed AIFF format that WMP will swallow.


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");


Although a long time since the last post, I found the answer to the problem user196004 was having not being able to save to a folder OTHER than the temporary folder.

AudioFileCreateWithURL takes a CFURLRef as input. If the url is created using CFURLCreateWithString, and the destination folder has any spaces in it, the creation of the url will fail (null).

The solution is to escape the string.

CFStringRef fileNameEscaped = CFURLCreateStringByAddingPercentEscapes( NULL, fileName, NULL, NULL, kCFStringEncodingUTF8 );

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜