I think you need to record audio using MediaRecorder
:
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();
public double getAmplitude() { if (mRecorder != null) return (mRecorder.getMaxAmplitude()); else return 0; }
To calculate the Db value:
powerDb = 20 * log10(getAmplitude() / referenceAmp);
Typically, a maximum signal value is selected as a reference amplitude. That is, we normalize the signal, so that the maximum amplitude is defined as 1 or 0 dB
source share