如何在Android录音时显示MIC输入可视化

时间:2014-08-26 07:17:38

标签: java android visualization audiorecord android-audiorecord

我正在寻找一种显示MIC输入电平语音强度的方法。 我使用Android AudioRecord录制语音输入。

我正在阅读本教程以供参考

http://developer.samsung.com/android/technical-docs/Displaying-Sound-Volume-in-Real-Time-While-Recording

我也将其实现为

while (isRecording) {
            read = recorder.read(data, 0, bufferSize);

            if (AudioRecord.ERROR_INVALID_OPERATION != read) {
                try {
                    os.write(data);                 


                     int amplitude = (data[0] & 0xff) << 8 | data[1];
                      amplitude = Math.abs(amplitude);
                      pbVisulaizer.setProgress(amplitude);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

但幅度变化过于频繁我也在根据录音质量寻找进度条的最大进度。任何建议。

1 个答案:

答案 0 :(得分:2)

https://github.com/Audioboo/audioboo-android/blob/master/src/fm/audioboo/application/FLACRecorder.java

有关在每个IO上捕获'getAmplitudes()'的编码器,请参阅#361,362

messageHandler是异步方式,可以返回到标准ProgressBar管理实际级别Meter的UI线程...

return new Handler(new Handler.Callback()
            {
                  public boolean handleMessage(Message m)
                  {
                    switch (m.what) {
                      case FLACRecorder.MSG_AMPLITUDES:
                        FLACRecorder.Amplitudes amp = (FLACRecorder.Amplitudes) m.obj;

                        // Create a copy of the amplitude in mLastAmplitudes; we'll use
                        // that when we restart recording to calculate the position
                        // within the Boo.
                        mLastAmplitudes = new FLACRecorder.Amplitudes(amp);
                        //TODO call the amp routine from the other process
                        if (null != mAmplitudes) {
                          amp.mPosition += mAmplitudes.mPosition;
                        }                                               
                 mProgressBar.setProgress((int)Math.round(mLastAmplitudes.mAverage * 10000));
}}}