Kaps
Kaps

Reputation: 2365

Android Speech Recognition for specific sound pitch

Can 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

Upvotes: 3

Views: 2570

Answers (2)

gregm
gregm

Reputation: 12169

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

Upvotes: 4

Justin Peel
Justin Peel

Reputation: 47082

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.

Upvotes: 2

Related Questions