如何在Android上对麦克风进行采样而不进行记录以获得实时幅度/电平? [英] How to sample microphone on Android without recording to get live amplitude/level?

查看:139
本文介绍了如何在Android上对麦克风进行采样而不进行记录以获得实时幅度/电平?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图像这样获取Android上麦克风的振幅水平:

I was trying to get the amplitude level of a microphone on Android like so:

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

Timer timer = new Timer();
timer.scheduleAtFixedRate(new RecorderTask(recorder), 0, 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());
    }
}

不幸的是,这始终只会返回0.

Unfortunately, this only returns 0 all the time.

要使此功能生效,我必须真正开始录制.正确吗?

It appears that for this to work I have to actually start recording. Is that correct?

如果是,我是否需要记录500毫秒,获取振幅,停止记录并重复?

If so, do I need to record for 500ms, get amplitude, stop recording and repeat?

最后,我必须记录到文件吗?我不需要保存此音频文件,难道我不能获取自上次调用当前现场麦克风输入以来的当前幅度或最高幅度吗?

Finally, do I have to record to a file? I do not need to save this audio file, can't I just get the current amplitude or highest amplitude since last call of the current live microphone input without recording?

感谢您的帮助.

推荐答案

是的,您必须首先调用recorder.start(),并且一定不要忘记最后也要调用recorder.stop()!

Yep you have to call recorder.start() first, and you must not forget to call recorder.stop() at the end too!

请参见对于示例应用程序http://code.google.com/p/android-labs/source/browse/trunk/NoiseAlert/src/com/google/android/noisealert/在SoundMeter.java和NoiseAlert.java中

See http://code.google.com/p/android-labs/source/browse/trunk/NoiseAlert/src/com/google/android/noisealert/ for an example application, you may want to take a look at SoundMeter.java and NoiseAlert.java

这篇关于如何在Android上对麦克风进行采样而不进行记录以获得实时幅度/电平?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆