tags:

views:

29

answers:

1

I want to detect blowing into the mic on android. Google wasn't much help. Is it possible?

+1  A: 

OK! I found this online, so it definitely seems possible. It looks like you can call mediaRecorder.getMaxAmplitude().

Code from an app called NoiseAlert

public void start() {
    if (mRecorder == null) {
        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        mRecorder.setOutputFile("/dev/null"); 
        mRecorder.prepare();
        mRecorder.start();
        mEMA = 0.0;
    }
}

public double getAmplitude() {
    if (mRecorder != null)
        return  (mRecorder.getMaxAmplitude()/2700.0);
    else
        return 0;
}

Here's the source

rob