机器人:检测音量 [英] android: Detect sound level
本文介绍了机器人:检测音量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 MediaRecorder
我捕捉设备的麦克风的声音。从我得到的声音我只需要分析音量(声音响度),而不保存声音文件。
两个问题:
- 如何获得响度的声音在给定时刻?
- 如何做的分析,不保存声音文件?
感谢您。
解决方案
-
使用
mRecorder.getMaxAmplitude();
-
有关的声音,但不保存所有你需要的是用分析
李>mRecorder.setOutputFile(的/ dev / null的);
Here's一个例子,我希望这有助于
公共类SoundMeter {
私人MediaRecorder mRecorder = NULL;
公共无效启动(){
如果(mRecorder == NULL){
mRecorder =新MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AMR_NB);
mRecorder.setOutputFile(的/ dev / null的);
mRecorder prepare()。
mRecorder.start();
}
}
公共无效停止(){
如果(mRecorder!= NULL){
mRecorder.stop();
mRecorder.release();
mRecorder = NULL;
}
}
公共双getAmplitude(){
如果(mRecorder!= NULL)
返回mRecorder.getMaxAmplitude();
其他
返回0;
}
}
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.
Two questions:
- How do I get the loudness for the sound at a given moment in time?
- How do I do the analyze without saving the sound to a file?
Thank you.
解决方案
Use
mRecorder.getMaxAmplitude();
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;
}
}
这篇关于机器人:检测音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文