title: How to detect silence when audio recording in android using AUDIORECORD
body: <p>Trying to detect silence. Used the following code. My objective is to convert all recorded data to .wav file which I  achieved, but now i want to make recording stop when detecting silence. Is this achievable?</p>
  
  <pre><code>mAud.startRecording();
              while (mIsRecording) {
                  ByteBuffer buffer = ByteBuffer.allocateDirect(mBufferSize * 2);
                  numSamples = mAud.read(buffer, mBufferSize * 2);
                  if (numSamples == AudioRecord.ERROR_INVALID_OPERATION) {
                      throw new IllegalStateException(
                              "read() returned AudioRecord.ERROR_INVALID_OPERATION");
                  } else if (numSamples == AudioRecord.ERROR_BAD_VALUE) {
                      throw new IllegalStateException(
                              "read() returned AudioRecord.ERROR_BAD_VALUE");
                  }
                  if (numSamples &gt; 0)
                      addBuffer(buffer, numSamples / 2);
              }
              mAud.stop();
              mAud.release();
  </code></pre>