我的目标是当用户在通话期间对着麦克风讲话时能够获得回叫/挂机。我不能使用RecognizerIntent.ACTION_RECOGNIZE_SPEECH,因为在电话呼叫期间,这将排队,直到呼叫结束,然后出现提示。我需要一些东西,当用户在电话上时,我可以确定他们是否对着话筒说话。如果没有本地方法,你能推荐第三方吗?
现在我正在使用android noiseAlert示例代码,它看起来像这样:
public class SoundMeter {
static final private double EMA_FILTER = 0.6;
private MediaRecorder mRecorder = null;
private double mEMA = 0.0;
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");
try {
mRecorder.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mRecorder.start();
mEMA = 0.0;
}
}
public void stop() {
if (mRecorder != null) {
mRecorder.stop();
mRecorder.release();
mRecorder = null;
}
}
public double getAmplitude() {
if (mRecorder != null)
return (mRecorder.getMaxAmplitude()/2700.0);
else
return 0;
}
public double getAmplitudeEMA() {
double amp = getAmplitude();
mEMA = EMA_FILTER * amp + (1.0 - EMA_FILTER) * mEMA;
return mEMA;
}
}
使用这种方法,我可以用什么来衡量用户正在使用麦克风讲话?例如,我可以执行以下操作:
SoundMeter soundMeter = new SoundMeter();
soundMeter.start();
if(soundMeter.getAmplitude>1.0)
//users is talking into the mic