Take a look at http://developer.android.com/reference/android/media/AudioRecord.html
When you read the buffer, byte values ββwill represent the amplitude. The higher the byte value, the louder the sound.
Here is a smaller version of what I used in an application that I wrote some time ago:
Add this to your mainifest.xml
<uses-permission android:name="android.permission.RECORD_AUDIO" />
soundlevel.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ToggleButton android:id="@+id/togglebutton_record" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ToggleButton" /> <ProgressBar android:id="@+id/progressbar_level" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
SoundLevel.java
import android.app.Activity; import android.media.AudioFormat; import android.media.AudioRecord; import android.media.MediaRecorder; import android.os.Bundle; import android.os.Handler; import android.os.SystemClock; import android.widget.CompoundButton; import android.widget.ProgressBar; import android.widget.ToggleButton; public class SoundLevel extends Activity { private static final int sampleRate = 11025; private static final int bufferSizeFactor = 10; private AudioRecord audio; private int bufferSize; private ProgressBar level; private Handler handler = new Handler(); private int lastLevel = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.soundlevel); level = (ProgressBar) findViewById(R.id.progressbar_level); level.setMax(32676); ToggleButton record = (ToggleButton) findViewById(R.id.togglebutton_record); record.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
jawsware
source share