我正在使用录音机以咖啡格式录制来自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” 还有channelLayout,一个Mono(错误的)和另一个“无通道布局”
请帮助我,我真的很失望..只是为了频道布局,我怎么没有频道?
答案 0 :(得分:0)
我使用[NSData dataWithBytes:nil length:0]而不是[NSData dataWithBytes:& 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];