开发者

Android Speech Recognition for specific sound pitch

Ca开发者_开发技巧n we detect 'scream' or 'loud sound' etc using Android Speech Recognition APIs? Or is there is any other software/third party tool that can do the same?

Thanks, Kaps


You mean implement a clapper?

There's no need to use fancy math or the speech recognition API. Just use the MediaRecorder and its getMaxAmplitute() method.

Here is some of code you'll need. The algorithm, records for a period of time and then measures the amplitute difference. If it is large, then the user probably made a loud sound.

public void recordClap()
{
    recorder.start();

    int startAmplitude = recorder.getMaxAmplitude();
    Log.d(D_LOG, "starting amplitude: " + startAmplitude);
boolean ampDiff;
do
{
    Log.d(D_LOG, "waiting while taking in input");
    waitSome();
    int finishAmplitude = 0;
    try
    {
        finishAmplitude = recorder.getMaxAmplitude();
    }
    catch (RuntimeException re)
    {
        Log.e(D_LOG, "unable to get the max amplitude " + re);
    }
    ampDiff = checkAmplitude(startAmplitude, finishAmplitude);
    Log.d(D_LOG, "finishing amp: " + finishAmplitude + " difference: " + ampDiff );
}
while (!ampDiff && recorder.isRecording());

}

private boolean checkAmplitude(int startAmplitude, int finishAmplitude)
{
    int ampDiff = finishAmplitude - startAmplitude;
    Log.d(D_LOG, "amplitude difference " + ampDiff);
    return (ampDiff >= 10000);
}


If I were trying to detect a scream or loud sound, I would just look for a high root-mean-squared of the sounds coming through the microphone. I suppose that you can try to train a speech recognition system to recognize a scream, but it seems like overkill.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜