ibm-watson-cognitive 在Java中使用WebSocket识别音频文件
示例
使用 Java-SDK 3.0.1
CountDownLatch lock = new CountDownLatch(1);SpeechToText service = new SpeechToText();
service.setUsernameAndPassword("<username>", "<password>");
FileInputStream audio = new FileInputStream("filename.wav");
RecognizeOptions options = new RecognizeOptions.Builder()
.continuous(true)
.interimResults(true)
.contentType(HttpMediaType.AUDIO_WAV)
.build();
service.recognizeUsingWebSocket(audio, options, new BaseRecognizeCallback() {
@Override
public void onTranscription(SpeechResults speechResults) {
System.out.println(speechResults);
if (speechResults.isFinal())
lock.countDown();
}
});
lock.await(1, TimeUnit.MINUTES);
以上是 ibm-watson-cognitive 在Java中使用WebSocket识别音频文件 的全部内容, 来源链接: utcz.com/z/315805.html