@@ -0,0 +1,2216 @@
+package com.ibm.watson.developer_cloud.speech_to_text.v1;%0A%0Aimport java.io.FileInputStream;%0Aimport java.io.FileNotFoundException;%0Aimport java.util.concurrent.CountDownLatch;%0Aimport java.util.concurrent.TimeUnit;%0A%0Aimport com.ibm.watson.developer_cloud.http.HttpMediaType;%0Aimport com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognizeOptions;%0Aimport com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechResults;%0Aimport com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.BaseRecognizeCallback;%0A%0A/**%0A * Recognize microphone input speech continuously using WebSockets.%0A */%0Apublic class MicrophoneWithWebSocketsExample %7B%0A  public static void main(String%5B%5D args) throws FileNotFoundException, InterruptedException %7B%0A    SpeechToText service = new SpeechToText();%0A    service.setUsernameAndPassword(%22%3Cusername%3E%22, %22%3Cpassword%3E%22);%0A%0A    // Signed PCM AudioFormat with 16kHz, 16 bit sample size, mono%0A    int sampleRate = 16000;%0A    AudioFormat format = new AudioFormat(sampleRate, 16, 1, true, false);%0A    DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);%0A%0A    if (!AudioSystem.isLineSupported(info)) %7B%0A      System.out.println(%22Line not supported%22);%0A      System.exit(0);%0A    %7D%0A%0A    TargetDataLine line = (TargetDataLine) AudioSystem.getLine(info);%0A    line.open(format);%0A    line.start();%0A%0A    AudioInputStream audio = new AudioInputStream(line);%0A%0A    RecognizeOptions options = new RecognizeOptions.Builder()%0A      .continuous(true)%0A      .interimResults(true)%0A      .timestamps(true)%0A      .wordConfidence(true)%0A      //.inactivityTimeout(5) // use this to stop listening when the speaker pauses, i.e. for 5s%0A      .contentType(HttpMediaType.AUDIO_RAW + %22; rate=%22 + sampleRate)%0A      .build();%0A%0A    service.recognizeUsingWebSocket(audio, options, new BaseRecognizeCallback() %7B%0A      @Override%0A      public void onTranscription(SpeechResults speechResults) %7B%0A        System.out.println(speechResults);%0A      %7D%0A    %7D);%0A%0A    System.out.println(%22Listening to your voice for the next 30s...%22);%0A    Thread.sleep(30 * 1000);%0A%0A    // closing the WebSockets underlying InputStream will close the WebSocket itself.%0A    line.stop();%0A    line.close();%0A%0A    System.out.println(%22Fin.%22);%0A  %7D%0A%7D%0A

Add speech-to-text Microphone + WebSocket example