How to check strength (intensity) of audio while recording?

旧街凉风 提交于 2019-12-09 05:51:00

问题


I am working on a voice recorder application. I want to know is there any way to find strength of the audio while recording it. I don't want to save the recording anywhere. I just want to show user if the sound being caught by the mic is louder then a predefined threshold or not.

Let's say if the sound being caught in below 2 decibel, it should show "low" in a red canvas. As soon as sound gets louder and passes 2 decibel threshold the canvas should turn green and show "high" message.

Is it possible using MediaRecorder or i haveto use AudioRecorder class. And how to work it out.

Thanks in advance


回答1:


You can start another thread when recording start and use getMaxAmplitude function to capture Amplitudes.

Below is the snippet.here we are taking sample for every 250 milliseconds and calculated max 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());
                } 

            }
        }


来源:https://stackoverflow.com/questions/11066470/how-to-check-strength-intensity-of-audio-while-recording

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!