Skip to content

Commit 211ac07

Browse files
[speech-to-text] Added Websocket example #15
1 parent 61a9909 commit 211ac07

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.ibm.watson.developer_cloud.speech_to_text.v1;
2+
3+
import java.io.FileInputStream;
4+
import java.io.FileNotFoundException;
5+
6+
import com.ibm.watson.developer_cloud.http.HttpMediaType;
7+
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechResults;
8+
import com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.BaseRecognizeDelegate;
9+
10+
/**
11+
* Recognize using WebSockets a sample wav file and print the transcript into the console output.
12+
*/
13+
public class RecognizeUsingWebSockets {
14+
public static void main(String[] args) throws FileNotFoundException {
15+
SpeechToText service = new SpeechToText();
16+
service.setUsernameAndPassword("<username>", "<password>");
17+
18+
FileInputStream audio = new FileInputStream("src/test/resources/speech_to_text/sample1.wav");
19+
20+
RecognizeOptions options =
21+
new RecognizeOptions().continuous(true).interimResults(true)
22+
.contentType(HttpMediaType.AUDIO_WAV);
23+
24+
service.recognizeUsingWebSockets(audio, options, new BaseRecognizeDelegate() {
25+
26+
@Override
27+
public void onMessage(SpeechResults speechResults) {
28+
System.out.println(speechResults);
29+
}
30+
});
31+
}
32+
}

0 commit comments

Comments
 (0)