<dependency> <groupId>com.ibm.watson</groupId> <artifactId>speech-to-text</artifactId> <version>7.4.0</version> </dependency>
'com.ibm.watson:speech-to-text:7.4.0'Use the Speech to Text service to recognize the text from a .wav file.
SpeechToText service = new SpeechToText(); IamOptions options = new IamOptions.Builder() .apiKey("<iam_api_key>") .build(); service.setIamCredentials(options); File audio = new File("src/test/resources/sample1.wav"); RecognizeOptions options = new RecognizeOptions.Builder() .audio(audio) .contentType(HttpMediaType.AUDIO_WAV) .build(); SpeechRecognitionResults transcript = service.recognize(options).execute().getResult(); System.out.println(transcript);
Speech to Text supports WebSocket, the url is: wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize
SpeechToText service = new SpeechToText(); IamOptions options = new IamOptions.Builder() .apiKey("<iam_api_key>") .build(); service.setIamCredentials(options); InputStream audio = new FileInputStream("src/test/resources/sample1.wav"); RecognizeOptions options = new RecognizeOptions.Builder() .audio(audio) .contentType(HttpMediaType.AUDIO_WAV) .interimResults(true) .build(); service.recognizeUsingWebSocket(options, new BaseRecognizeCallback() { @Override public void onTranscription(Response<SpeechRecognitionResults> speechResults) { System.out.println(speechResults); } }); // wait 20 seconds for the asynchronous response Thread.sleep(20000);