iLBC 形式でオーディオを録音するにはどうすればよいですか? Question # 1010343から助けを得て、次のコードを実装しました。
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] initWithCapacity:10];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
// [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey]; // doesn't work: no error, but no sound
// [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatiLBC] forKey:AVFormatIDKey]; // doesn't work: no error, but not sound
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordSetting setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey];
[recordSetting setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setObject:[NSNumber numberWithInt: AVAudioQualityHigh] forKey: AVEncoderAudioQualityKey];
recorder = [[AVAudioRecorder alloc] initWithURL:audioFile settings:recordSetting error: &avError ];
[recorder setDelegate:self];
[recorder recordForDuration:(NSTimeInterval) secLeft];
[recorder record];
上記のように、それはうまくいきます。良い録音。簡単再生。他の形式がコメントアウトされていることに気付きます。どちらかを試しても、何も得られません。より小さなファイルが必要で、質問 # 7279643によると、次の貴重な情報が得られます。
Here are the results for few encoding supported by iPhone:
Size of audio file of duration 10 sec.
kAudioFormatMPEG4AAC : 164 kB
kAudioFormatAppleLossless : 430 kB
kAudioFormatAppleIMA4 : 475 kB
kAudioFormatULaw : 889 kB
kAudioFormatALaw : 889 KB
iLBCに記録できるはずです。しかし、試しても何も得られません。IMA4 フォーマット以外のフォーマットを使用する場合、録音または再生で変更する必要があるものはありますか?
これが私の再生コードです:
NSError *avError;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&avError];
[audioSession setActive:YES error:&avError];
if( !avError ) {
if( [audioPlayer isPlaying] ) {
[audioPlayer stop ];
}
while( ![audioPlayer isPlaying] ) {
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFile error:nil];
self.audioPlayer = player;
self.audioPlayer.numberOfLoops = 0;
[audioPlayer prepareToPlay];
[audioPlayer play];
}
} else {
NSLog(@"Playback Error: %@", avError );
}