SpeechToText extends BaseService { public WebSocket recognizeUsingWebSocket( RecognizeOptions recognizeOptions, RecognizeCallback callback) { com.ibm.cloud.sdk.core.util.Validator.notNull( recognizeOptions, "recognizeOptions cannot be null"); com.ibm.cloud.sdk.core.util.Validator.notNull(recognizeOptions.audio(), "audio cannot be null"); com.ibm.cloud.sdk.core.util.Validator.notNull(callback, "callback cannot be null"); HttpUrl.Builder urlBuilder = HttpUrl.parse(getServiceUrl() + "/v1/recognize").newBuilder(); if (recognizeOptions.model() != null) { urlBuilder.addQueryParameter("model", recognizeOptions.model()); } if (recognizeOptions.customizationId() != null) { urlBuilder.addQueryParameter("customization_id", recognizeOptions.customizationId()); } if (recognizeOptions.languageCustomizationId() != null) { urlBuilder.addQueryParameter( "language_customization_id", recognizeOptions.languageCustomizationId()); } if (recognizeOptions.acousticCustomizationId() != null) { urlBuilder.addQueryParameter( "acoustic_customization_id", recognizeOptions.acousticCustomizationId()); } if (recognizeOptions.baseModelVersion() != null) { urlBuilder.addQueryParameter("base_model_version", recognizeOptions.baseModelVersion()); } String url = urlBuilder.toString().replace("https: Request.Builder builder = new Request.Builder().url(url); setAuthentication(builder); setDefaultHeaders(builder); OkHttpClient client = configureHttpClient(); return client.newWebSocket( builder.build(), new SpeechToTextWebSocketListener(recognizeOptions, callback)); } SpeechToText();  SpeechToText(Authenticator authenticator);  SpeechToText(String serviceName);  SpeechToText(String serviceName, Authenticator authenticator); ServiceCall<SpeechModels> listModels(ListModelsOptions listModelsOptions); ServiceCall<SpeechModels> listModels(); ServiceCall<SpeechModel> getModel(GetModelOptions getModelOptions); ServiceCall<SpeechRecognitionResults> recognize(RecognizeOptions recognizeOptions); WebSocket recognizeUsingWebSocket(
      RecognizeOptions recognizeOptions, RecognizeCallback callback); ServiceCall<RegisterStatus> registerCallback(
      RegisterCallbackOptions registerCallbackOptions); ServiceCall<Void> unregisterCallback(UnregisterCallbackOptions unregisterCallbackOptions); ServiceCall<RecognitionJob> createJob(CreateJobOptions createJobOptions); ServiceCall<RecognitionJobs> checkJobs(CheckJobsOptions checkJobsOptions); ServiceCall<RecognitionJobs> checkJobs(); ServiceCall<RecognitionJob> checkJob(CheckJobOptions checkJobOptions); ServiceCall<Void> deleteJob(DeleteJobOptions deleteJobOptions); ServiceCall<LanguageModel> createLanguageModel(
      CreateLanguageModelOptions createLanguageModelOptions); ServiceCall<LanguageModels> listLanguageModels(
      ListLanguageModelsOptions listLanguageModelsOptions); ServiceCall<LanguageModels> listLanguageModels(); ServiceCall<LanguageModel> getLanguageModel(
      GetLanguageModelOptions getLanguageModelOptions); ServiceCall<Void> deleteLanguageModel(
      DeleteLanguageModelOptions deleteLanguageModelOptions); ServiceCall<TrainingResponse> trainLanguageModel(
      TrainLanguageModelOptions trainLanguageModelOptions); ServiceCall<Void> resetLanguageModel(ResetLanguageModelOptions resetLanguageModelOptions); ServiceCall<Void> upgradeLanguageModel(
      UpgradeLanguageModelOptions upgradeLanguageModelOptions); ServiceCall<Corpora> listCorpora(ListCorporaOptions listCorporaOptions); ServiceCall<Void> addCorpus(AddCorpusOptions addCorpusOptions); ServiceCall<Corpus> getCorpus(GetCorpusOptions getCorpusOptions); ServiceCall<Void> deleteCorpus(DeleteCorpusOptions deleteCorpusOptions); ServiceCall<Words> listWords(ListWordsOptions listWordsOptions); ServiceCall<Void> addWords(AddWordsOptions addWordsOptions); ServiceCall<Void> addWord(AddWordOptions addWordOptions); ServiceCall<Word> getWord(GetWordOptions getWordOptions); ServiceCall<Void> deleteWord(DeleteWordOptions deleteWordOptions); ServiceCall<Grammars> listGrammars(ListGrammarsOptions listGrammarsOptions); ServiceCall<Void> addGrammar(AddGrammarOptions addGrammarOptions); ServiceCall<Grammar> getGrammar(GetGrammarOptions getGrammarOptions); ServiceCall<Void> deleteGrammar(DeleteGrammarOptions deleteGrammarOptions); ServiceCall<AcousticModel> createAcousticModel(
      CreateAcousticModelOptions createAcousticModelOptions); ServiceCall<AcousticModels> listAcousticModels(
      ListAcousticModelsOptions listAcousticModelsOptions); ServiceCall<AcousticModels> listAcousticModels(); ServiceCall<AcousticModel> getAcousticModel(
      GetAcousticModelOptions getAcousticModelOptions); ServiceCall<Void> deleteAcousticModel(
      DeleteAcousticModelOptions deleteAcousticModelOptions); ServiceCall<TrainingResponse> trainAcousticModel(
      TrainAcousticModelOptions trainAcousticModelOptions); ServiceCall<Void> resetAcousticModel(ResetAcousticModelOptions resetAcousticModelOptions); ServiceCall<Void> upgradeAcousticModel(
      UpgradeAcousticModelOptions upgradeAcousticModelOptions); ServiceCall<AudioResources> listAudio(ListAudioOptions listAudioOptions); ServiceCall<Void> addAudio(AddAudioOptions addAudioOptions); ServiceCall<AudioListing> getAudio(GetAudioOptions getAudioOptions); ServiceCall<Void> deleteAudio(DeleteAudioOptions deleteAudioOptions); ServiceCall<Void> deleteUserData(DeleteUserDataOptions deleteUserDataOptions);  }
@Test public void testClosingInputStreamClosesWebSocket() throws Exception { TestRecognizeCallback callback = new TestRecognizeCallback(); WebSocketRecorder webSocketRecorder = new WebSocketRecorder("server"); PipedOutputStream outputStream = new PipedOutputStream(); InputStream inputStream = new PipedInputStream(outputStream); server.enqueue(new MockResponse().withWebSocketUpgrade(webSocketRecorder)); String customizationId = "id"; String version = "version"; Double customizationWeight = 0.1; RecognizeOptions options = new RecognizeOptions.Builder() .audio(inputStream) .contentType(HttpMediaType.createAudioRaw(44000)) .customizationId(customizationId) .baseModelVersion(version) .customizationWeight(customizationWeight) .build(); service.recognizeUsingWebSocket(options, callback); WebSocket serverSocket = webSocketRecorder.assertOpen(); serverSocket.send("{\"state\": {}}"); outputStream.write(ByteString.encodeUtf8("test").toByteArray()); outputStream.close(); webSocketRecorder.assertTextMessage( "{\"content-type\":\"audio/l16; rate=44000\"," + "\"customization_weight\":0.1,\"action\":\"start\"}"); webSocketRecorder.assertBinaryMessage(ByteString.encodeUtf8("test")); webSocketRecorder.assertTextMessage("{\"action\":\"stop\"}"); webSocketRecorder.assertExhausted(); serverSocket.close(1000, null); callback.assertConnected(); callback.assertDisconnected(); callback.assertNoErrors(); callback.assertOnTranscriptionComplete(); }