0

I was trying to get the amplitude level of a microphone on Android like so:

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

Timer timer = new Timer();
timer.scheduleAtFixedRate(new RecorderTask(recorder), 0, 1000);

private class RecorderTask extends TimerTask {
    private MediaRecorder recorder;

    public RecorderTask(MediaRecorder recorder) {
        this.recorder = recorder;
    }

    public void run() {
        Log.v("MicInfoService", "amplitude: " + recorder.getMaxAmplitude());
    }
}

Unfortunately, this only returns 0 all the time.

It appears that for this to work I have to actually start recording. Is that correct?

If so, do I need to record for 500ms, get amplitude, stop recording and repeat?

Finally, do I have to record to a file? I do not need to save this audio file, can't I just get the current amplitude or highest amplitude since last call of the current live microphone input without recording?

Any help is appreciated, thanks.

1 Answers1

0

Yes, you have to start recording. If you aren't recording, there's no signal to find an amplitude of.

No, you do not need to stop recording, getMaxAmplitude finds the max amplitude since the last time you called it.

Yes, with this api you have to write to a file. You could delete the file when done though. Or try using /dev/null as a file.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127