我想在语音检测方面采取一些方法。
例如,
就像在PragDuck
app中一样,当用户开始讲话时duck
开始动画。
如何检测用户的声音?
答案 0 :(得分:5)
使用AVAudioRecorder - 音频计量 - 结帐本教程 - 当用户吹入麦克风http://mobileorchard.com/tutorial-detecting-when-a-user-blows-into-the-mic/
时检查快速示例:
_audioRecorder.meteringEnabled = YES;
//1. This method will get the current mic activity and will format it to a 0 - 1 scale.
-(void)checkRecordingMeters:(NSTimer *)timer
{
[_audioRecorder updateMeters];
const double ALPHA = 0.2;
float peakPower = [_audioRecorder peakPowerForChannel:0];
double peakPowerForChannel = pow(10, (0.05 * peakPower));
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;
NSLog(@"Meters: %f" , peakPower);
NSLog(@"lowPassResults: %f \n" , lowPassResults);
}
//2. Call this method to run a loop timer to check the current mic activity
-(void)enableMettering:(BOOL)enable
{
if(enable)
{
levelTimer = [[NSTimer scheduledTimerWithTimeInterval:0.03
target:self
selector:@selector(checkRecordingMeters:)
userInfo:nil
repeats:YES] retain];
}
else
{
[levelTimer invalidate];
[levelTimer release];
}
}
答案 1 :(得分:1)
您可以使用AudioQueue记录并添加简单的阈值过滤器以忽略环境噪音。为了降低延迟,您可以使用AudioUnit。