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:
Thank you.
Shazam (free; all smartphones): This app recognizes recorded songs—popular or not.
Use mRecorder.getMaxAmplitude();
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; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With