我正在使用录音机以caf格式录制iPhone中的声音。然后,我希望它是wav格式。所以我用网上的一个代码进行转换:
AudioChannelLayout channelLayout;
memset(&channelLayout, 0, sizeof(AudioChannelLayout));
channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
NSMutableDictionary *outputSettings = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:audioFormat], AVFormatIDKey,
[NSNumber numberWithFloat:16000.0], AVSampleRateKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSData dataWithBytes:&channelLayout length:sizeof(AudioChannelLayout)], AVChannelLayoutKey,
nil];
但问题是文件get是这样的:(afinfo)
File type ID: WAVE
Num Tracks: 1
----
Data format: 1 ch, 16000 Hz, 'lpcm' (0x0000000C) 16-bit little-endian signed integer
Channel layout: Mono
estimated duration: 2.229125 sec
audio bytes: 71332
audio packets: 35666
bit rate: 256000 bits per second
packet size upper bound: 2
maximum packet size: 2
audio data file offset: 4096
optimized
source bit depth: I16
我需要一个这样的文件:
File type ID: WAVE
Num Tracks: 1
----
Data format: 1 ch, 16000 Hz, 'lpcm' (0x0000000C) 16-bit little-endian signed integer
no channel layout.
estimated duration: 2.229125 sec
audio bytes: 71332
audio packets: 35666
bit rate: 256000 bits per second
packet size upper bound: 2
maximum packet size: 2
audio data file offset: 44
optimized
source bit depth: I16
正如你所看到的,主要的区别是一个是"音频数据文件偏移量:44",另一个是"音频数据文件偏置量:4096"还有信道布局,一个单声道(错误)和另一个"没有信道布局"
请帮帮我,我真的很失望。。就频道布局而言,我怎么可能没有频道?
我使用了[NSData dataWithBytes:nil length:0]而不是[NSData data WithBytes:&channelLayout length:sizeof(AudioChannelLayout)],这导致了没有频道布局。
NSMutableDictionary *outputSettings = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:audioFormat], AVFormatIDKey,
[NSNumber numberWithFloat:16000.0], AVSampleRateKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSData dataWithBytes:nil length:0], AVChannelLayoutKey,
nil];