English 中文(简体)
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 seem 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 );





相关问题
Playing a Sound With Monotouch

No matter what I try (build -> content, NSUrl, filename) I get a null exception : file not found when I try to play a .caf sound file in monotouch. //var path = NSBundle.MainBundle.PathForResource("...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

Play sound in iPhone web app with Javascript?

I m currently creating an iPhone web application for piano chords, and I wanted to add an option that would let the user press a Play button and play the selected chord. However, I m not sure how to ...

热门标签