Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android--Mic input levels?

Tags:

android

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

like image 610
rob Avatar asked Aug 20 '10 20:08

rob


1 Answers

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

like image 160
rob Avatar answered Sep 27 '22 02:09

rob