34
34
import com .google .cloud .speech .v1 .SpeechGrpc ;
35
35
import com .google .protobuf .ByteString ;
36
36
import com .google .protobuf .TextFormat ;
37
+
37
38
import io .grpc .ManagedChannel ;
38
39
import io .grpc .StatusRuntimeException ;
39
40
import io .grpc .auth .ClientAuthInterceptor ;
40
41
import io .grpc .netty .NegotiationType ;
41
42
import io .grpc .netty .NettyChannelBuilder ;
43
+
44
+ import org .apache .commons .cli .CommandLine ;
45
+ import org .apache .commons .cli .CommandLineParser ;
46
+ import org .apache .commons .cli .DefaultParser ;
47
+ import org .apache .commons .cli .OptionBuilder ;
48
+ import org .apache .commons .cli .Options ;
49
+ import org .apache .commons .cli .ParseException ;
50
+
42
51
import java .io .IOException ;
43
52
import java .nio .file .Files ;
44
53
import java .nio .file .Path ;
45
54
import java .nio .file .Paths ;
46
55
import java .util .Arrays ;
47
56
import java .util .List ;
48
- import java .util .concurrent .CountDownLatch ;
49
57
import java .util .concurrent .Executors ;
50
58
import java .util .concurrent .TimeUnit ;
51
59
import java .util .logging .Level ;
52
60
import java .util .logging .Logger ;
53
- import org .apache .commons .cli .CommandLine ;
54
- import org .apache .commons .cli .CommandLineParser ;
55
- import org .apache .commons .cli .DefaultParser ;
56
- import org .apache .commons .cli .Options ;
57
- import org .apache .commons .cli .OptionBuilder ;
58
- import org .apache .commons .cli .ParseException ;
59
61
60
62
/**
61
63
* Client that sends audio to Speech.NonStreamingRecognize and returns transcript.
62
64
*/
63
65
public class NonStreamingRecognizeClient {
64
66
65
67
private static final Logger logger =
66
- Logger .getLogger (NonStreamingRecognizeClient .class .getName ());
68
+ Logger .getLogger (NonStreamingRecognizeClient .class .getName ());
67
69
68
- private static final List <String > OAUTH2_SCOPES =
69
- Arrays .asList ("https://www.googleapis.com/auth/xapi.zoo" );
70
+ private static final List <String > OAUTH2_SCOPES =
71
+ Arrays .asList ("https://www.googleapis.com/auth/xapi.zoo" );
70
72
71
73
private final String host ;
72
74
private final int port ;
@@ -76,8 +78,11 @@ public class NonStreamingRecognizeClient {
76
78
private final ManagedChannel channel ;
77
79
private final SpeechGrpc .SpeechBlockingStub blockingStub ;
78
80
79
- /** Construct client connecting to Cloud Speech server at {@code host:port}. */
80
- public NonStreamingRecognizeClient (String host , int port , String file , int samplingRate ) throws IOException {
81
+ /**
82
+ * Construct client connecting to Cloud Speech server at {@code host:port}.
83
+ */
84
+ public NonStreamingRecognizeClient (String host , int port , String file , int samplingRate )
85
+ throws IOException {
81
86
this .host = host ;
82
87
this .port = port ;
83
88
this .file = file ;
@@ -134,7 +139,7 @@ public void recognize() {
134
139
135
140
public static void main (String [] args ) throws Exception {
136
141
137
- String audio_file = "" ;
142
+ String audioFile = "" ;
138
143
String host = "speech.googleapis.com" ;
139
144
Integer port = 443 ;
140
145
Integer sampling = 16000 ;
@@ -166,7 +171,7 @@ public static void main(String[] args) throws Exception {
166
171
try {
167
172
CommandLine line = parser .parse (options , args );
168
173
if (line .hasOption ("file" )) {
169
- audio_file = line .getOptionValue ("file" );
174
+ audioFile = line .getOptionValue ("file" );
170
175
} else {
171
176
System .err .println ("An Audio file path must be specified (e.g. /foo/baz.raw)." );
172
177
System .exit (1 );
@@ -192,14 +197,13 @@ public static void main(String[] args) throws Exception {
192
197
System .err .println ("An Audio sampling rate must be specified." );
193
198
System .exit (1 );
194
199
}
195
- }
196
- catch (ParseException exp ) {
200
+ } catch (ParseException exp ) {
197
201
System .err .println ("Unexpected exception:" + exp .getMessage ());
198
202
System .exit (1 );
199
203
}
200
204
201
205
NonStreamingRecognizeClient client =
202
- new NonStreamingRecognizeClient (host , port , audio_file , sampling );
206
+ new NonStreamingRecognizeClient (host , port , audioFile , sampling );
203
207
try {
204
208
client .recognize ();
205
209
} finally {
0 commit comments