Java – Android: the sampling microphone does not record to obtain real-time amplitude / level?
I'm trying to get the microphone amplitude level on Android:
MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); Timer timer = new Timer(); timer.scheduleAtFixedRate(new RecorderTask(recorder),1000); private class RecorderTask extends TimerTask { private MediaRecorder recorder; public RecorderTask(MediaRecorder recorder) { this.recorder = recorder; } public void run() { Log.v("MicInfoService","amplitude: " + recorder.getMaxAmplitude()); } }
Unfortunately, this will only always return 0
It seems that for this job, I must actually start recording Is that right?
If so, do I need to record 500ms, get the amplitude, stop recording and repeat?
Finally, do I have to record to a file? I don't need to save this audio file. I can't get the current amplitude or maximum amplitude from the last call input by the current microphone without recording?
Thank you for any help
resolvent
Solution
Yes, you must call recorder first Start (), you can't forget to call recorder. at the end. stop()!
For a sample application, see http://code.google.com/p/android-labs/source/browse/trunk/NoiseAlert/src/com/google/android/noisealert/ , you may need to check soundmeter Java and noisealert java
The above is the Java Android collected by programming house for you: the sampling microphone is not recorded to obtain real-time amplitude / level? I hope this article can help you solve Java Android: sampling microphone does not record to obtain real-time amplitude / level? Program development problems encountered.
If you think the content of the programming home website is good, you are welcome to recommend the programming home website to programmers and friends.