I'm trying to detect when there is too much auditory noise. I'm new to Android, and I don't know how to do detect external noise levels.
An attempt I tried was to display the value of noise using the recorder
methods: getAudioSource
and getMaxAmplitude
methods.
public void startRecording() throws IOException {
numeSunet=Environment.getExternalStorageDirectory().getPath()+"/"+System.currentTimeMillis()+".3gp";
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(Environment.getExternalStorageDirectory().getPath()+"/"+System.currentTimeMillis()+".3gp");
recorder.prepare();
recorder.start();
int x = recorder.getMaxAmplitude();
snt.setText(""+x);
}public void stopRecording() {
recorder.stop();
recorder.release();
}
In my case, y is always 0, and x is always 8. I would appreciate if somebody knows how to detect audio noise levels in android.