检测到iPhone麦克风吹? [英] Detecting blowing on the iPhone microphone?

查看:147
本文介绍了检测到iPhone麦克风吹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测用户何时吹入iPhone的麦克风。现在我正在使用来自 Stephen Celis的SCListener类致电

I am trying to detect when the user is blowing into the mic of an iPhone. Right now I am using the SCListener class from Stephen Celis to call

if ([[SCListener sharedListener] peakPower] > 0.99)

。但是,当我不吹时,这有时会返回。任何人都有任何示例代码来检查用户是否正在进入麦克风?

in an NSTimer. However, this returns true sometimes when I'm not blowing. Anyone have any sample code to check if the user is blowing into the mic?

推荐答案

我建议首先对功率信号进行低通滤波。总会有一些瞬态噪声会使瞬时读数变得混乱;低通滤波有助于缓解这种情况。一个漂亮而简单的低通滤波器就是这样的:

I would recommend low-pass filtering the power signal first. There is always going to be some amount of transient noise that will mess with instantaneous readings; low-pass filtering helps mitigate that. A nice and easy low-pass filter would be something like this:

// Make this a global variable, or a member of your class:
double micPower = 0.0;
// Tweak this value to your liking (must be between 0 and 1)
const double ALPHA = 0.05;

// Do this every 'tick' of your application (e.g. every 1/30 of a second)
double instantaneousPower = [[SCListener sharedListener] peakPower];

// This is the key line in computing the low-pass filtered value
micPower = ALPHA * instantaneousPower + (1.0 - ALPHA) * micPower;

if(micPower > THRESHOLD)  // 0.99, in your example
    // User is blowing on the microphone

这篇关于检测到iPhone麦克风吹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆