user3472378
user3472378

Reputation:

How to show MIC input visualization while audio recording Android

i am looking for a way to show MIC input level voice strength. i Am using Android AudioRecord to record voice input.

i am following this tutorial for reference

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

i have implemented this also as

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();
                }
            }
        }

but the amplitude changing is too frequent i am also looking for a maximum progress of progress bar according to recording quality. any suggestions.

Upvotes: 3

Views: 4499

Answers (1)

Robert Rowntree
Robert Rowntree

Reputation: 6289

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

see #361, 362 for an encoder that captures 'getAmplitudes()' on every IO

The messageHandler is async way to get back to the UI thread where a standard ProgressBar manages the actual level Meter...

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));
}}}

Upvotes: 3

Related Questions