title: Android Audio Record Voice Activity Detection
body: <p>How to implement voice activity detection for voice signal received in form of byteArray. How to check whether the received signal has speech or not?
  The current implementation of android code which receives audio in form of byte Array is :   </p>
  
  <pre><code> public class AudioRecordActivity extends AppCompatActivity {
  
      private static final int RECORDER_BPP = 16;
      private static final int RECORDER_SAMPLERATE = 8000;
      private static final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_STEREO;
      private static final int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
      short[] audioData;
      int[] bufferData;
      int bytesRecorded;
      private AudioRecord recorder = null;
      private int bufferSize = 0;
      private Thread recordingThread = null;
      private boolean isRecording = false;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_audio_record);
  
  
          ActivityCompat.requestPermissions(AudioRecordActivity.this,
                  new String[]{Manifest.permission.RECORD_AUDIO},
                  1);
  
  
          Button startRecording = (Button) findViewById(R.id.startRecording);
          bufferSize = AudioRecord.getMinBufferSize
                  (RECORDER_SAMPLERATE, RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING) * 3;
  
          audioData = new short[bufferSize]; //short array that pcm data is put into.
          Toast.makeText(this, "buffer size"+bufferSize, Toast.LENGTH_SHORT).show();
  
      }
  
      public void startRecording(View view) {
          recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
                  RECORDER_SAMPLERATE,
                  RECORDER_CHANNELS,
                  RECORDER_AUDIO_ENCODING,
                  bufferSize);
          int i = recorder.getState();
          if (i == 1)
              recorder.startRecording();
  
          isRecording = true;
  
          recordingThread = new Thread(new Runnable() {
              @Override
              public void run() {
                  writeAudioDataToFile();
              }
          }, "AudioRecorder Thread");
  
          recordingThread.start();
      }
  
      public void stopRecording(View view) {
          if (null != recorder) {
              isRecording = false;
  
              int i = recorder.getState();
              if (i == 1)
                  recorder.stop();
              recorder.release();
  
              recorder = null;
              recordingThread = null;
          }
      }
  
      private void writeAudioDataToFile() {
          byte data[] = new byte[bufferSize];
  
  
  
          int read = 0;
          while (isRecording) {
              read = recorder.read(data, 0, bufferSize);
             /* if (read &gt; 0) {
              }
  
              if (AudioRecord.ERROR_INVALID_OPERATION != read) {
                  try {
                      os.write(data);
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }*/
              Log.d("buffersize", bufferSize + "");
              Log.d("data", Arrays.toString(data));
          }
  
  
  
      }
  
  
      }
  }
  </code></pre>
  
  <p>How to implement VAD in android?</p>