2014-11-21 91 views
2

我使用AVAssetWriter与这些设置在应用程序中的临时文件夹输出wav文件:如何使用AVAssetWriter在ios中写入正确的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]; 

它的输出看似正常的45MB的.wav文件,但应用程序无法反正读它。我怀疑文件头是损坏的,因为我打开了.avav的audacity(它接受了它没有问题),并再次用.wav扩展名重新导出它。导出的文件在应用程序中正常工作。

我还用文本编辑器打开了这两个.wav文件来查看标题,它们有些不同。

任何线索?

回答

0

当您应该使用kAudioFormatLinearPCM时,您正在使用kAudioFormatMPEG4AAC代替AVFormatIDKey。波形文件是PCM格式,不能用MPEG-4数据包导出。

相关问题