File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
examples/java/com/ibm/watson/developer_cloud/speech_to_text/v1 Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments