Query noise level in Android

2019-03-11 09:20发布

I want to develop a small Android app to measure the current noise level (probablyin dB). But I have no idea what to look for in the libs. I don't want to record the noise. Can someone give me a pointer what classes to look at?

3条回答
Ridiculous、
2楼-- · 2019-03-11 09:52

The following code snippet shows how we obtained the noise level in the past. Unfortunately the documentation does not tell what unit #getMaxAmplitude() returns.

// Start recording but don't store data
MediaRecorder mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setOutputFile("/dev/null");
mediaRecorder.prepare();
mediaRecorder.start();

// Obtain maximum amplitude since last call of getMaxAmplitude()
while(someCondition) {
    int amplitude = mediaRecorder.getMaxAmplitude();
}

// Don't forget to release
mediaRecorder.reset();
mediaRecorder.release();
查看更多
可以哭但决不认输i
3楼-- · 2019-03-11 10:15

I recommend looking in these classes:

android.media.AudioFormat
android.media.AudioManager
android.media.AudioTrack

We used them in the Blinkendroid audio package a short while ago.

查看更多
趁早两清
4楼-- · 2019-03-11 10:15

For me 'maxAmplitude' was not helpful. After day of researching I eventually reached my target. You can find my solution here: Android: AudioRecord Class Problem: Callback is never called

查看更多
登录 后发表回答