Get the Microphone sound level ( Decibel level) in Android










0















Im quite new to android and i have searched about this for quite a while. I would like to build an application that is something like a decibel meter. In realtime it shows the sound level. It there is much noise in the room, there will be something indicating that, if its quiet something will indicate that!.



I don't have any idea at all how to do this. Could anyone explain what the basics of the microphone-sound-level application? If its possible, maybe provide some code?



Thanks!










share|improve this question


























    0















    Im quite new to android and i have searched about this for quite a while. I would like to build an application that is something like a decibel meter. In realtime it shows the sound level. It there is much noise in the room, there will be something indicating that, if its quiet something will indicate that!.



    I don't have any idea at all how to do this. Could anyone explain what the basics of the microphone-sound-level application? If its possible, maybe provide some code?



    Thanks!










    share|improve this question
























      0












      0








      0


      2






      Im quite new to android and i have searched about this for quite a while. I would like to build an application that is something like a decibel meter. In realtime it shows the sound level. It there is much noise in the room, there will be something indicating that, if its quiet something will indicate that!.



      I don't have any idea at all how to do this. Could anyone explain what the basics of the microphone-sound-level application? If its possible, maybe provide some code?



      Thanks!










      share|improve this question














      Im quite new to android and i have searched about this for quite a while. I would like to build an application that is something like a decibel meter. In realtime it shows the sound level. It there is much noise in the room, there will be something indicating that, if its quiet something will indicate that!.



      I don't have any idea at all how to do this. Could anyone explain what the basics of the microphone-sound-level application? If its possible, maybe provide some code?



      Thanks!







      java android






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 25 '11 at 22:05









      SebSeb

      2613813




      2613813






















          3 Answers
          3






          active

          oldest

          votes


















          0














          There's a great app in the marketplace called Audalyzer



          http://code.google.com/p/moonblink/wiki/Audalyzer



          Also check this discussion..



          Android: sample microphone without recording to get live amplitude/level?






          share|improve this answer




















          • 1





            This is not the answer, the guy is clearly asking how to build the app. He's not looking for apps

            – chntgomez
            Sep 2 '17 at 16:49


















          0














          This question has been addressed generally for Java, and the required classes are available in Android.



          The basic idea is to sample the data line for the microphone, and calculate the level from the returned buffer.



          How to calculate the level/amplitude/db of audio signal in java?



          You can also have a look at the Visualizer class which does FFT frequency analysis, however the permissions for microphone may not be consistent across various devices. You may also have to connect it to the Equalizer class to access the mic.



          https://developer.android.com/reference/android/media/audiofx/Visualizer.html






          share|improve this answer






























            0














            You can use MediaRecorder.getMaxAmplitude().



            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) 

            ActivityCompat.requestPermissions(this, new StringManifest.permission.RECORD_AUDIO,
            RECORD_AUDIO);




            1. Get the noise level using the 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");
              try
              mRecorder.prepare();
              catch (IllegalStateException e)
              e.printStackTrace();
              catch (IOException e)
              e.printStackTrace();

              mRecorder.start();



            2. Start the MediaRecorder,



              private Runnable mSleepTask = new Runnable() 
              public void run()
              //Log.i("Noise", "runnable mSleepTask");
              mSensor.start();
              if (!mWakeLock.isHeld())
              mWakeLock.acquire();

              //Noise monitoring start
              // Runnable(mPollTask) will execute after POLL_INTERVAL
              mHandler.postDelayed(mPollTask, POLL_INTERVAL);

              ;



            3. Create Runnable Thread to check the noise level frequently,



              private Runnable mPollTask = new Runnable() 
              public void run()
              double amp = mSensor.getAmplitude();
              //Log.i("Noise", "runnable mPollTask");
              // Runnable(mPollTask) will again execute after POLL_INTERVAL
              mHandler.postDelayed(mPollTask, POLL_INTERVAL);

              ;


            Convert the Amplitude to decibel using the following formula,



            return 20 * Math.log10(mRecorder.getMaxAmplitude() / 2700.0);



            1. Monitoring the Voice and Alert for the Louder Noise.



              // Create runnable thread to Monitor Voice
              private Runnable mPollTask = new Runnable()
              public void run()
              double amp = mSensor.getAmplitude();
              //Log.i("Noise", "runnable mPollTask");
              updateDisplay("Monitoring Voice...", amp);

              if ((amp > mThreshold))
              callForHelp(amp);
              //Log.i("Noise", "==== onCreate ===");

              // Runnable(mPollTask) will again execute after POLL_INTERVAL
              mHandler.postDelayed(mPollTask, POLL_INTERVAL);

              ;






            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7197798%2fget-the-microphone-sound-level-decibel-level-in-android%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              There's a great app in the marketplace called Audalyzer



              http://code.google.com/p/moonblink/wiki/Audalyzer



              Also check this discussion..



              Android: sample microphone without recording to get live amplitude/level?






              share|improve this answer




















              • 1





                This is not the answer, the guy is clearly asking how to build the app. He's not looking for apps

                – chntgomez
                Sep 2 '17 at 16:49















              0














              There's a great app in the marketplace called Audalyzer



              http://code.google.com/p/moonblink/wiki/Audalyzer



              Also check this discussion..



              Android: sample microphone without recording to get live amplitude/level?






              share|improve this answer




















              • 1





                This is not the answer, the guy is clearly asking how to build the app. He's not looking for apps

                – chntgomez
                Sep 2 '17 at 16:49













              0












              0








              0







              There's a great app in the marketplace called Audalyzer



              http://code.google.com/p/moonblink/wiki/Audalyzer



              Also check this discussion..



              Android: sample microphone without recording to get live amplitude/level?






              share|improve this answer















              There's a great app in the marketplace called Audalyzer



              http://code.google.com/p/moonblink/wiki/Audalyzer



              Also check this discussion..



              Android: sample microphone without recording to get live amplitude/level?







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 23 '17 at 12:32









              Community

              11




              11










              answered Nov 24 '11 at 14:54









              timemirrortimemirror

              476411




              476411







              • 1





                This is not the answer, the guy is clearly asking how to build the app. He's not looking for apps

                – chntgomez
                Sep 2 '17 at 16:49












              • 1





                This is not the answer, the guy is clearly asking how to build the app. He's not looking for apps

                – chntgomez
                Sep 2 '17 at 16:49







              1




              1





              This is not the answer, the guy is clearly asking how to build the app. He's not looking for apps

              – chntgomez
              Sep 2 '17 at 16:49





              This is not the answer, the guy is clearly asking how to build the app. He's not looking for apps

              – chntgomez
              Sep 2 '17 at 16:49













              0














              This question has been addressed generally for Java, and the required classes are available in Android.



              The basic idea is to sample the data line for the microphone, and calculate the level from the returned buffer.



              How to calculate the level/amplitude/db of audio signal in java?



              You can also have a look at the Visualizer class which does FFT frequency analysis, however the permissions for microphone may not be consistent across various devices. You may also have to connect it to the Equalizer class to access the mic.



              https://developer.android.com/reference/android/media/audiofx/Visualizer.html






              share|improve this answer



























                0














                This question has been addressed generally for Java, and the required classes are available in Android.



                The basic idea is to sample the data line for the microphone, and calculate the level from the returned buffer.



                How to calculate the level/amplitude/db of audio signal in java?



                You can also have a look at the Visualizer class which does FFT frequency analysis, however the permissions for microphone may not be consistent across various devices. You may also have to connect it to the Equalizer class to access the mic.



                https://developer.android.com/reference/android/media/audiofx/Visualizer.html






                share|improve this answer

























                  0












                  0








                  0







                  This question has been addressed generally for Java, and the required classes are available in Android.



                  The basic idea is to sample the data line for the microphone, and calculate the level from the returned buffer.



                  How to calculate the level/amplitude/db of audio signal in java?



                  You can also have a look at the Visualizer class which does FFT frequency analysis, however the permissions for microphone may not be consistent across various devices. You may also have to connect it to the Equalizer class to access the mic.



                  https://developer.android.com/reference/android/media/audiofx/Visualizer.html






                  share|improve this answer













                  This question has been addressed generally for Java, and the required classes are available in Android.



                  The basic idea is to sample the data line for the microphone, and calculate the level from the returned buffer.



                  How to calculate the level/amplitude/db of audio signal in java?



                  You can also have a look at the Visualizer class which does FFT frequency analysis, however the permissions for microphone may not be consistent across various devices. You may also have to connect it to the Equalizer class to access the mic.



                  https://developer.android.com/reference/android/media/audiofx/Visualizer.html







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 4 '17 at 23:41









                  Dominic CerisanoDominic Cerisano

                  1,4351831




                  1,4351831





















                      0














                      You can use MediaRecorder.getMaxAmplitude().



                      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) 

                      ActivityCompat.requestPermissions(this, new StringManifest.permission.RECORD_AUDIO,
                      RECORD_AUDIO);




                      1. Get the noise level using the 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");
                        try
                        mRecorder.prepare();
                        catch (IllegalStateException e)
                        e.printStackTrace();
                        catch (IOException e)
                        e.printStackTrace();

                        mRecorder.start();



                      2. Start the MediaRecorder,



                        private Runnable mSleepTask = new Runnable() 
                        public void run()
                        //Log.i("Noise", "runnable mSleepTask");
                        mSensor.start();
                        if (!mWakeLock.isHeld())
                        mWakeLock.acquire();

                        //Noise monitoring start
                        // Runnable(mPollTask) will execute after POLL_INTERVAL
                        mHandler.postDelayed(mPollTask, POLL_INTERVAL);

                        ;



                      3. Create Runnable Thread to check the noise level frequently,



                        private Runnable mPollTask = new Runnable() 
                        public void run()
                        double amp = mSensor.getAmplitude();
                        //Log.i("Noise", "runnable mPollTask");
                        // Runnable(mPollTask) will again execute after POLL_INTERVAL
                        mHandler.postDelayed(mPollTask, POLL_INTERVAL);

                        ;


                      Convert the Amplitude to decibel using the following formula,



                      return 20 * Math.log10(mRecorder.getMaxAmplitude() / 2700.0);



                      1. Monitoring the Voice and Alert for the Louder Noise.



                        // Create runnable thread to Monitor Voice
                        private Runnable mPollTask = new Runnable()
                        public void run()
                        double amp = mSensor.getAmplitude();
                        //Log.i("Noise", "runnable mPollTask");
                        updateDisplay("Monitoring Voice...", amp);

                        if ((amp > mThreshold))
                        callForHelp(amp);
                        //Log.i("Noise", "==== onCreate ===");

                        // Runnable(mPollTask) will again execute after POLL_INTERVAL
                        mHandler.postDelayed(mPollTask, POLL_INTERVAL);

                        ;






                      share|improve this answer





























                        0














                        You can use MediaRecorder.getMaxAmplitude().



                        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) 

                        ActivityCompat.requestPermissions(this, new StringManifest.permission.RECORD_AUDIO,
                        RECORD_AUDIO);




                        1. Get the noise level using the 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");
                          try
                          mRecorder.prepare();
                          catch (IllegalStateException e)
                          e.printStackTrace();
                          catch (IOException e)
                          e.printStackTrace();

                          mRecorder.start();



                        2. Start the MediaRecorder,



                          private Runnable mSleepTask = new Runnable() 
                          public void run()
                          //Log.i("Noise", "runnable mSleepTask");
                          mSensor.start();
                          if (!mWakeLock.isHeld())
                          mWakeLock.acquire();

                          //Noise monitoring start
                          // Runnable(mPollTask) will execute after POLL_INTERVAL
                          mHandler.postDelayed(mPollTask, POLL_INTERVAL);

                          ;



                        3. Create Runnable Thread to check the noise level frequently,



                          private Runnable mPollTask = new Runnable() 
                          public void run()
                          double amp = mSensor.getAmplitude();
                          //Log.i("Noise", "runnable mPollTask");
                          // Runnable(mPollTask) will again execute after POLL_INTERVAL
                          mHandler.postDelayed(mPollTask, POLL_INTERVAL);

                          ;


                        Convert the Amplitude to decibel using the following formula,



                        return 20 * Math.log10(mRecorder.getMaxAmplitude() / 2700.0);



                        1. Monitoring the Voice and Alert for the Louder Noise.



                          // Create runnable thread to Monitor Voice
                          private Runnable mPollTask = new Runnable()
                          public void run()
                          double amp = mSensor.getAmplitude();
                          //Log.i("Noise", "runnable mPollTask");
                          updateDisplay("Monitoring Voice...", amp);

                          if ((amp > mThreshold))
                          callForHelp(amp);
                          //Log.i("Noise", "==== onCreate ===");

                          // Runnable(mPollTask) will again execute after POLL_INTERVAL
                          mHandler.postDelayed(mPollTask, POLL_INTERVAL);

                          ;






                        share|improve this answer



























                          0












                          0








                          0







                          You can use MediaRecorder.getMaxAmplitude().



                          if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) 

                          ActivityCompat.requestPermissions(this, new StringManifest.permission.RECORD_AUDIO,
                          RECORD_AUDIO);




                          1. Get the noise level using the 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");
                            try
                            mRecorder.prepare();
                            catch (IllegalStateException e)
                            e.printStackTrace();
                            catch (IOException e)
                            e.printStackTrace();

                            mRecorder.start();



                          2. Start the MediaRecorder,



                            private Runnable mSleepTask = new Runnable() 
                            public void run()
                            //Log.i("Noise", "runnable mSleepTask");
                            mSensor.start();
                            if (!mWakeLock.isHeld())
                            mWakeLock.acquire();

                            //Noise monitoring start
                            // Runnable(mPollTask) will execute after POLL_INTERVAL
                            mHandler.postDelayed(mPollTask, POLL_INTERVAL);

                            ;



                          3. Create Runnable Thread to check the noise level frequently,



                            private Runnable mPollTask = new Runnable() 
                            public void run()
                            double amp = mSensor.getAmplitude();
                            //Log.i("Noise", "runnable mPollTask");
                            // Runnable(mPollTask) will again execute after POLL_INTERVAL
                            mHandler.postDelayed(mPollTask, POLL_INTERVAL);

                            ;


                          Convert the Amplitude to decibel using the following formula,



                          return 20 * Math.log10(mRecorder.getMaxAmplitude() / 2700.0);



                          1. Monitoring the Voice and Alert for the Louder Noise.



                            // Create runnable thread to Monitor Voice
                            private Runnable mPollTask = new Runnable()
                            public void run()
                            double amp = mSensor.getAmplitude();
                            //Log.i("Noise", "runnable mPollTask");
                            updateDisplay("Monitoring Voice...", amp);

                            if ((amp > mThreshold))
                            callForHelp(amp);
                            //Log.i("Noise", "==== onCreate ===");

                            // Runnable(mPollTask) will again execute after POLL_INTERVAL
                            mHandler.postDelayed(mPollTask, POLL_INTERVAL);

                            ;






                          share|improve this answer















                          You can use MediaRecorder.getMaxAmplitude().



                          if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) 

                          ActivityCompat.requestPermissions(this, new StringManifest.permission.RECORD_AUDIO,
                          RECORD_AUDIO);




                          1. Get the noise level using the 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");
                            try
                            mRecorder.prepare();
                            catch (IllegalStateException e)
                            e.printStackTrace();
                            catch (IOException e)
                            e.printStackTrace();

                            mRecorder.start();



                          2. Start the MediaRecorder,



                            private Runnable mSleepTask = new Runnable() 
                            public void run()
                            //Log.i("Noise", "runnable mSleepTask");
                            mSensor.start();
                            if (!mWakeLock.isHeld())
                            mWakeLock.acquire();

                            //Noise monitoring start
                            // Runnable(mPollTask) will execute after POLL_INTERVAL
                            mHandler.postDelayed(mPollTask, POLL_INTERVAL);

                            ;



                          3. Create Runnable Thread to check the noise level frequently,



                            private Runnable mPollTask = new Runnable() 
                            public void run()
                            double amp = mSensor.getAmplitude();
                            //Log.i("Noise", "runnable mPollTask");
                            // Runnable(mPollTask) will again execute after POLL_INTERVAL
                            mHandler.postDelayed(mPollTask, POLL_INTERVAL);

                            ;


                          Convert the Amplitude to decibel using the following formula,



                          return 20 * Math.log10(mRecorder.getMaxAmplitude() / 2700.0);



                          1. Monitoring the Voice and Alert for the Louder Noise.



                            // Create runnable thread to Monitor Voice
                            private Runnable mPollTask = new Runnable()
                            public void run()
                            double amp = mSensor.getAmplitude();
                            //Log.i("Noise", "runnable mPollTask");
                            updateDisplay("Monitoring Voice...", amp);

                            if ((amp > mThreshold))
                            callForHelp(amp);
                            //Log.i("Noise", "==== onCreate ===");

                            // Runnable(mPollTask) will again execute after POLL_INTERVAL
                            mHandler.postDelayed(mPollTask, POLL_INTERVAL);

                            ;







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Dec 21 '18 at 3:59









                          Simon Corcos

                          334219




                          334219










                          answered Aug 13 '18 at 4:16









                          Tung DuongTung Duong

                          745216




                          745216



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7197798%2fget-the-microphone-sound-level-decibel-level-in-android%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              How to read a connectionString WITH PROVIDER in .NET Core?

                              Node.js Script on GitHub Pages or Amazon S3

                              Museum of Modern and Contemporary Art of Trento and Rovereto