How to check the strength (intensity) of sound during recording?

I am working on a voice recorder application. I want to know if there is a way to find the power of sound during recording. I do not want to record anywhere. I just want to show the user if the sound caught by the microphone is louder than the predetermined threshold or not.

Say, if the sound falls below 2 decibels, it should show β€œlow” in red canvas. As soon as the sound becomes louder and passes 2 decibel thresholds, the canvas should turn green and show a "high" message.

Is it possible to use MediaRecorder or to use the AudioRecorder class. And how to do it.

Thanks in advance

+6
source share
1 answer

You can start another stream at the start of recording and use the getMaxAmplitude function to capture amplitudes.

Below is a snippet. We take a sample for every 250 milliseconds and calculate the maximum amplitude

 public void run() { int i = 0; while(i == 0) { try { sleep(250); } catch (InterruptedException e) { e.printStackTrace(); } if (mRecorder != null) { amplitude = mRecorder.getMaxAmplitude(); //Here you can put condition (low/high) Log.i("AMPLITUDE", new Integer(amplitude).toString()); } } } 
+9
source

Source: https://habr.com/ru/post/918254/


All Articles