我想使用iPhone SDK检测每秒音频文件的幅度(以dB为单位)。根据每秒声音文件的dB大小,我需要此功能用于对象的嘴动画。我怎样才能做到这一点 ?有可能使用哪种音频框架? 你有任何例子的链接吗?
答案 0 :(得分:4)
我找到了解决这个问题的方法
我使用AVAudioPlayer的peakPowerForChannel和averagePowerForChannel方法获取装饰
AVAudioPlayer *avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:recordedTmpFile error:&error];
avPlayer.delegate = self;
avPlayer.meteringEnabled = YES;
[avPlayer prepareToPlay];
[avPlayer play];
NSTimer *levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.03 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
此方法返回peakPowerForChannel和averagePowerForChannel
- (void)levelTimerCallback:(NSTimer *)timer {
[avPlayer updateMeters];
NSLog(@"Peak left: %f Avg right: %f", [avPlayer peakPowerForChannel:0],[avPlayer averagePowerForChannel:0]);
}
答案 1 :(得分:1)
看起来不错,不知道任何iPhone编程虽然抱歉: http://www.politepix.com/2010/06/18/decibel-metering-from-an-iphone-audio-unit/