docs: @Override
    public void onOpen(final WebSocket socket, Response response) {
      callback.onConnected();
      this.socket = socket;
      if (!socket.send(buildStartMessage(options))) {
        callback.onError(new IOException("WebSocket unavailable"));
      } else {
        // Send the InputStream on a different Thread. Elsewise, interim results cannot be
        // received,
        // because the Thread that called SpeechToText.recognizeUsingWebSocket is blocked.
        audioThread = new Thread(AUDIO_TO_WEB_SOCKET) {
          @Override
          public void run() {
            sendInputStream(stream);
            // Do not send the stop message if the socket has been closed already, for example because of the
            // inactivity timeout.
            // If the socket is still open after the sending finishes, for example because the user closed the
            // microphone AudioInputStream, send a stop message.
            if (socketOpen && !socket.send(buildStopMessage())) {
              LOG.log(Level.SEVERE, "Stop message discarded because WebSocket is unavailable");
            }
          }
        };
  
        audioThread.start();
      }
    }