I was wondering how I could check the volume level from the mic... If that makes sense. IE: In a quiet room say it returns a 0, but when someone speaks it would return 10!
A thread was started here, but hasn't had much luck: http://www.anddev.org/viewtopic.php?p=25656
Basically, I want to measure a normal level and then trigger an event when there is more noise.
I have tried a little of what was posted in the mentioned thread:
Using java Syntax Highlighting
- AudioRecord ar;
- boolean running;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- running = false;
- int src = AudioSource.MIC;
- int sr = 44100;
- int ch = AudioFormat.CHANNEL_CONFIGURATION_DEFAULT;
- int af = AudioFormat.ENCODING_PCM_16BIT;
- try {
- ar = new AudioRecord(src,sr,ch,af,AudioRecord.getMinBufferSize(sr, ch, af));
- startListening();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void startListening() {
- ar.startRecording();
- Thread t = new Thread() {
- public void run() {
- int test = 2;
- test++;
- for (int y = 0; y < 5; y ++) {
- short[] sho = new short[1];
- sho[0] = 10;
- int x = ar.read(sho, 256, 256);
- if (x > 0)
- tHandler.sendMessage(Message.obtain(tHandler, 1));
- }
- }
- };
- t.start();
- }
- private Handler tHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case 1:
- TextView tv = (TextView)findViewById(R.id.textLabel);
- tv.setText("High");
- ar.stop();
- break;
- }
- }
- };
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
The values (particularly the ones used in ar.read()), are all thumb sucked. I have no clue what I was inputing or what I was expecting to get out!
Does anyone have any insight for me?
Thanks in advance
Neil



