Sound recognition in Android

后端 未结 4 2035

I want my Android app to recognize sound. For example I want to know if the sound from microphone is a clapping or knocking or something else.

Do I need to use math,

4条回答
  •  攒了一身酷
    2020-12-04 12:09

    Musicg library is useful for whistle detection. Concerning claps, I wouldn't recommend use it, cause it reacts to every loud sound (even speech).

    For clap and other percussive sounds detection I recommend TarsosDSP. It has a simple API with a rich functionality (pitch detection and so on). For clap detection you can use something like (if you use TarsosDSPAndroid-v3):

    MicrophoneAudioDispatcher mDispatcher = new MicrophoneAudioDispatcher((int) SAMPLE_RATE, BUFFER_SIZE, BUFFER_OVERLAP);
    double threshold = 8;
    double sensitivity = 20;
    mPercussionDetector = new PercussionOnsetDetector(22050, 1024, 
            new OnsetHandler() {
    
                @Override
                public void handleOnset(double time, double salience) {
                    Log.d(TAG, "Clap detected!");
                }
            }, sensitivity, threshold);
    mDispatcher.addAudioProcessor(mPercussionDetector);
    new Thread(mDispatcher).start();
    

    You can tune your detector by adjusting sensitivity (0-100) and threshold (0-20).

    Good luck!

提交回复
热议问题