android:检测声级 [英] android: Detect sound level
本文介绍了android:检测声级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 MediaRecorder
我从设备的麦克风捕获声音.从我得到的声音中,我只需要分析音量(声音响度),而无需将声音保存到文件中.
Using MediaRecorder
I capture sound from device's microphone. From the sound I get I need only to analyze the sound volume (sound loudness), without saving the sound to a file.
两个问题:
- 如何获得特定时刻声音的响度?
- 如何在不将声音保存到文件的情况下进行分析?
谢谢.
推荐答案
使用
mRecorder.getMaxAmplitude();
为了在不保存的情况下分析声音,您只需要使用 mRecorder.setOutputFile("/dev/null");
For the analysis of sound without saving all you need is use mRecorder.setOutputFile("/dev/null");
举个例子,希望能帮到你
Here´s an example, I hope this helps
public class SoundMeter {
private MediaRecorder mRecorder = null;
public void start() {
if (mRecorder == null) {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile("/dev/null");
mRecorder.prepare();
mRecorder.start();
}
}
public void stop() {
if (mRecorder != null) {
mRecorder.stop();
mRecorder.release();
mRecorder = null;
}
}
public double getAmplitude() {
if (mRecorder != null)
return mRecorder.getMaxAmplitude();
else
return 0;
}
}
这篇关于android:检测声级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文