gpt4 book ai didi

iphone - 我想要 iLBC 格式,但似乎只能录制 IMA4 格式的音频

转载 作者:可可西里 更新时间:2023-11-01 06:16:22 28 4
gpt4 key购买 nike

如何以 iLBC 格式录制音频?我从问题 # 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 ,它提供了这个有值(value)的信息:

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 );
}

最佳答案

通过删除修复它:

[recordSetting setValue:[NSNumber numberWithFloat:44100.0]forKey:AVSampleRateKey]; 
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey]

我猜它们与 iLBC 默认值冲突。

关于iphone - 我想要 iLBC 格式,但似乎只能录制 IMA4 格式的音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13098632/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com