gpt4 book ai didi

iphone - 如何在 iphone 中检测麦克风的打击而不是语音?

转载 作者:太空狗 更新时间:2023-10-30 03:53:21 25 4
gpt4 key购买 nike

我正在使用此代码来检测打击。

可是我受不了了。我有声音。

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

但是没有声音。

最佳答案

您必须尝试使用​​低通结果。试试这个:

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

关于iphone - 如何在 iphone 中检测麦克风的打击而不是语音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13286768/

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