rob
rob

Reputation: 4109

Android--Mic input levels?

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

Upvotes: 5

Views: 3750

Answers (1)

rob
rob

Reputation: 4109

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

Upvotes: 7

Related Questions