I am trying to incorporate IBM Watson Speech-to-Text API to a GUI project. I am using an example code (shown below) provided in their documentation to make the request for transcription. I copied this code into a method and modified it a bit, and I get the results with no problem in the console. I am trying to send the transcription as a String to the GUI. The problem is that the program closes because of the System.out(0). What can I do to stop the execution of this method after I get the results without System.out(0)?
SpeechToText speechToText = new SpeechToText(authenticator);
speechToText.setServiceUrl("{url}");
try {
RecognizeOptions recognizeOptions = new RecognizeOptions.Builder()
.audio(new FileInputStream("audio-file.flac"))
.contentType("audio/flac")
.model("en-US_BroadbandModel")
.keywords(Arrays.asList("colorado", "tornado", "tornadoes"))
.keywordsThreshold((float) 0.5)
.maxAlternatives(3)
.build();
BaseRecognizeCallback baseRecognizeCallback =
new BaseRecognizeCallback() {
@Override
public void onTranscription
(SpeechRecognitionResults speechRecognitionResults) {
System.out.println(speechRecognitionResults);
}
@Override
public void onDisconnected() {
System.exit(0);
}
};
speechToText.recognizeUsingWebSocket(recognizeOptions,
baseRecognizeCallback);
} catch (FileNotFoundException e) {
e.printStackTrace();
}