iphone – iPad上的AVAudioRecorder米延迟
发布时间:2020-12-14 17:48:51 所属栏目:百科 来源:网络整理
导读:我无法从AVAudioRecorder获得准确的抄表(在iPad上进行测试). 在音量上升时似乎工作正常,但是当音量下降时会发生延迟.例如:我对着麦克风说话,然后慢慢提高声音.正如我所希望的那样,读数从-35.567增加到-34.678到-10.579,但是当我停止说话时,它会延迟1到2秒,
我无法从AVAudioRecorder获得准确的抄表(在iPad上进行测试).
在音量上升时似乎工作正常,但是当音量下降时会发生延迟.例如:我对着麦克风说话,然后慢慢提高声音.正如我所希望的那样,读数从-35.567增加到-34.678到-10.579,但是当我停止说话时,它会延迟1到2秒,然后再下降到-35.567(或者无论发生什么). 我已经添加了下面代码的要点,如果需要,我很乐意提供完整的代码. 我像这样初始化录音机: AVAudioSession * audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &error]; [audioSession setActive:YES error: &error]; NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init]; [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey]; [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey]; recordedTmpFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent: [NSString stringWithString: @"Recording.caf"]]]; recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error]; [recorder setDelegate:self]; [recorder prepareToRecord]; [recorder setMeteringEnabled:YES]; [recorder record]; 并循环更新仪表: -(void) loop:(ccTime)dt { if(isRecording == YES) { //get volume levels [recorder updateMeters]; float level = [recorder peakPowerForChannel:0]; NSLog(@"Vol: %f",level); } } 编辑:我还应该提到我正在使用循环的Cocos2d计划: [self schedule:@selector(loop:)]; 有什么想法会有这么长的延迟? 编辑:我已尝试使用平均峰值功率,这没有延迟.所以我可以用它作为一种解决方法.但是我宁愿不使用和平均峰值功率,也很好理解发生了什么. 解决方法
我敢肯定,大多数人已经想到这一点,但如果你想减少你的计量延迟,你需要使用AudioQueue或RemoteIO.在这里看到更好的解释:
Confusion with meters in AVAudioRecorder (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |