code: @Override
    public void onMessage(WebSocket webSocket, String message) {
      JsonObject json = new JsonParser().parse(message).getAsJsonObject();
      if (json.has(ERROR)) {
        String error = json.get(ERROR).getAsString();
  
        // Only call onError() if a real error occurred. The STT service sends
        // {"error" : "No speech detected for 5s"} for valid timeouts, configured by
        // RecognizeUsingWebSocketOptions.Builder.inactivityTimeout()
        if (!error.startsWith(TIMEOUT_PREFIX)) {
          callback.onError(new RuntimeException(error));
        } else {
          // notify that the service timeouts because of inactivity
          callback.onInactivityTimeout(new RuntimeException(error));
        }
      } else if (json.has(RESULTS) || json.has(SPEAKER_LABELS)) {
        callback.onTranscription(GSON.fromJson(message, SpeechRecognitionResults.class));
  
      } else if (json.has(STATE)) {
        // A listen state after everything has been sent over indicates everything has been processed
        if (!isListening) {
          isListening = true;
        } else {
          callback.onTranscriptionComplete();
          socket.close(CLOSE_NORMAL, "Transcription completed");
          return;
        }
  
        // notify that the service is ready to receive audio
        callback.onListening();
      }
    }
docs: /*
  (non-Javadoc)
  @see okhttp3.WebSocketListener#onMessage(okhttp3.WebSocket, java.lang.String)