简体   繁体   English

如何使用AVAssetWriter在ios中写出正确的WAV音频?

[英]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: 我正在使用AVAssetWriter在app temp文件夹中使用以下设置输出wav文件:

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. 它输出看似正常的45mb .wav文件,但应用无论如何都无法读取它。 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. 我怀疑文件头已损坏,因为我在大胆中打开了.wav(接受它没有问题)并再次使用.wav扩展名重新导出它。 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. 我还使用文本编辑器打开了两个.wav文件以查看标题,它们有些不同。

any clues? 任何线索?

You're using kAudioFormatMPEG4AAC for AVFormatIDKey when you should be using kAudioFormatLinearPCM . 您正在使用kAudioFormatMPEG4AACAVFormatIDKey时,你应该使用kAudioFormatLinearPCM Wave files are a PCM format and cannot be exported with MPEG-4 packets. Wave文件是PCM格式,无法使用MPEG-4数据包导出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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