@Override public void run(){
  try {
    audioLine.open();
    audioLine.start();
    audioLine.flush();
    AudioFormat format=audioLine.getFormat();
    byte[] buffer=new byte[4000];
    while (audioLine.isOpen()) {
      boolean systemTurnBeforeRead=outputSpeech != null;
      int numBytesRead=audioLine.read(buffer,0,buffer.length);
      if (systemTurnBeforeRead && outputSpeech == null) {
        audioLine.drain();
        continue;
      }
 else       if (outputSpeech != null || numBytesRead == 0 || (!voiceActivityDetection && inputSpeech == null)) {
        if (speechPanel != null) {
          speechPanel.clearVolume();
        }
        continue;
      }
      double rms=AudioUtils.getRMS(buffer,format);
      currentVolume=(currentVolume + rms) / 2;
      if (rms < backgroundVolume) {
        backgroundVolume=rms;
      }
 else {
        backgroundVolume+=(rms - backgroundVolume) * 0.003;
      }
      if (speechPanel != null) {
        speechPanel.updateVolume((int)currentVolume);
      }
      double difference=currentVolume - backgroundVolume;
      if (voiceActivityDetection && inputSpeech == null && difference > VOLUME_THRESHOLD) {
        startRecording();
      }
      if (inputSpeech != null && !inputSpeech.isFinal()) {
        inputSpeech.write(buffer);
        if (voiceActivityDetection && difference < VOLUME_THRESHOLD / 10) {
          stopRecording();
        }
      }
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}

@ Override public void run ( ) { try { audioLine . open ( ) ; audioLine . start ( ) ; audioLine . flush ( ) ; AudioFormat format = audioLine . getFormat ( ) ; byte [ ] buffer = new byte [ 4000 ] ; while ( audioLine . isOpen ( ) ) { boolean systemTurnBeforeRead = outputSpeech != null ; int numBytesRead = audioLine . read ( buffer , 0 , buffer . length ) ; if ( systemTurnBeforeRead && outputSpeech == null ) { audioLine . drain ( ) ; continue ; } else if ( outputSpeech != null || numBytesRead == 0 || ( ! voiceActivityDetection && inputSpeech == null ) ) { if ( speechPanel != null ) { speechPanel . clearVolume ( ) ; } continue ; } double rms = AudioUtils . getRMS ( buffer , format ) ; currentVolume = ( currentVolume + rms ) / 2 ; if ( rms < backgroundVolume ) { backgroundVolume = rms ; } else { backgroundVolume += ( rms - backgroundVolume ) * 0.003 ; } if ( speechPanel != null ) { speechPanel . updateVolume ( ( int ) currentVolume ) ; } double difference = currentVolume - backgroundVolume ; if ( voiceActivityDetection && inputSpeech == null && difference > VOLUME_THRESHOLD ) { startRecording ( ) ; } if ( inputSpeech != null && ! inputSpeech . isFinal ( ) ) { inputSpeech . write ( buffer ) ; if ( voiceActivityDetection && difference < VOLUME_THRESHOLD / 10 ) { stopRecording ( ) ; } } } } catch ( Exception e ) { e . printStackTrace ( ) ; } }
captures the audio data in the audio line and updates the data array .
