简体   繁体   中英

How do I use AVAssetWriter to write correct WAV audio out in ios?

I'm using AVAssetWriter to output wav file in the app temp folder with these settings:

NSDictionary*  outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                      [ NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
                                      [ NSNumber numberWithInt: 2 ], AVNumberOfChannelsKey,
                                      [ NSNumber numberWithFloat: 44100.0 ], AVSampleRateKey,
                                      [ NSData data ], AVChannelLayoutKey,
                                      [ NSNumber numberWithInt: 64000 ], AVEncoderBitRateKey,
                                      nil];

It's outputting seemingly normal 45mb .wav file but the app can not read it anyways. I suspect the file header is corrupt because I opened the the .wav in audacity (which accepted it no problem) and re-exported it with again .wav extension. The exported file worked fine in the app.

I also opened the both .wav files with the text editor to see the headers and they were somewhat different.

any clues?

You're using kAudioFormatMPEG4AAC for AVFormatIDKey when you should be using kAudioFormatLinearPCM . Wave files are a PCM format and cannot be exported with MPEG-4 packets.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM