Query noise level in Android

本小妞迷上赌 提交于 2019-12-02 21:09:22

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.

soul

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

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();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!