安卓:不记录,以获取实时的幅度/电平样品麦克风? [英] Android: sample microphone without recording to get live amplitude/level?

查看:347
本文介绍了安卓:不记录,以获取实时的幅度/电平样品麦克风?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让麦克风的幅度水平在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?

任何帮助是AP preciated,谢谢。

Any help is appreciated, thanks.

推荐答案

是的,你必须先调用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!

请参阅<一href="http://$c$c.google.com/p/android-labs/source/browse/trunk/NoiseAlert/src/com/google/android/noisealert/">http://$c$c.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

这篇关于安卓:不记录,以获取实时的幅度/电平样品麦克风?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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