Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: Detect sound level

Tags:

android

audio

Using MediaRecorder I capture sound from device's microphone. From the sound I get I need only to analyze the sound volume (sound loudness), without saving the sound to a file.

Two questions:

  1. How do I get the loudness for the sound at a given moment in time?
  2. How do I do the analyze without saving the sound to a file?

Thank you.

like image 402
Zelter Ady Avatar asked Jan 06 '13 11:01

Zelter Ady


People also ask

Is there an app that can detect sounds?

Shazam (free; all smartphones): This app recognizes recorded songs—popular or not.


1 Answers

  1. Use mRecorder.getMaxAmplitude();

  2. For the analysis of sound without saving all you need is use mRecorder.setOutputFile("/dev/null");

Here´s an example, I hope this helps

public class SoundMeter {      private MediaRecorder mRecorder = null;      public void start() {             if (mRecorder == null) {                     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 void stop() {             if (mRecorder != null) {                     mRecorder.stop();                            mRecorder.release();                     mRecorder = null;             }     }      public double getAmplitude() {             if (mRecorder != null)                     return  mRecorder.getMaxAmplitude();             else                     return 0;      } } 
like image 115
Ana Llera Avatar answered Sep 20 '22 03:09

Ana Llera