<dependency>
<groupId>com.ibm.watson</groupId>
<artifactId>speech-to-text</artifactId>
<version>14.0.0</version>
</dependency>
'com.ibm.watson:speech-to-text:14.0.0'
Use the Speech to Text service to recognize the text from a .wav file.
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
SpeechToText service = new SpeechToText(authenticator);
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://api.us-south.speech-to-text.watson.cloud.ibm.com/v1/recognize
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
SpeechToText service = new SpeechToText(authenticator);
InputStream audio = new FileInputStream("src/test/resources/sample1.wav");
RecognizeOptions options = new RecognizeOptions.Builder()
.audio(audio)
.contentType(HttpMediaType.AUDIO_WAV)
.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);