Reputation: 33
I'm trying to implement a sound meter in dB in android but I haven't found the way to start yet. I have gone over androids API and haven't found anything that I think is suitable. Can anyone help me please?
Upvotes: 3
Views: 4234
Reputation: 30832
This isn't possible in general because of the confusion between the different meanings of 'dB' and the fact that you can't measure physical Sound Pressure Level (which is generally what people mean when they talk about 'sound meters') without calibrated devices. See my previous answers to similar questions:
Upvotes: 3
Reputation: 2527
Try using AudioRecord to record the audio to a buffer, then measure the dB's from the raw PCM data.
To initialize AudioRecord
AudioRecord record = new AudioRecord(AudioSource.MIC, SAMPLING_RATE, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
To read a sample from MIC
short[] buff = new short[8000];
record.read(buff, 0, buff.length);
Upvotes: 2