Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect blow from mic not voice in iphone?

i'm using this code to detect blow.

but i cant get the blow. i got voice.

 NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:

                          [NSNumber numberWithFloat: 44100.0],                 AVSampleRateKey,
                          [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
                          [NSNumber numberWithInt: 1],                         AVNumberOfChannelsKey,
                          [NSNumber numberWithInt: AVAudioQualityMax],         AVEncoderAudioQualityKey,
                          nil];

NSError *error;

recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];

if (recorder) {
    [recorder prepareToRecord];
    recorder.meteringEnabled = YES;
    [recorder record];

    levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.3 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
} else
    NSLog(@"error %@",[error description]);

But got voice not blow.

like image 590
jpd Avatar asked Oct 22 '22 03:10

jpd


1 Answers

You kind of have to play with the low pass results. Try this:

- (void)levelTimerCallback:(NSTimer *)timer {
    [recorder updateMeters];

    const double ALPHA = 0.05;
    double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
    lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;  
    //NSLog(@"%f", lowPassResults);
    if (lowPassResults > 0.55)
        NSLog(@"Mic blow detected");
}
like image 82
Nate Lee Avatar answered Nov 01 '22 10:11

Nate Lee