Skip to content

Commit e747f5e

Browse files
tswastJerjou Cheng
authored andcommitted
speech: use shared checkstyle plugin.
I change the Speech API sample pom.xml to use the common parent, this means we now inherit the shared checkstyle configuration. I also fix the checkstyle errors in the Java code. Change-Id: I577f0489cb6c235223ae4428b590ae86820e1ec1
1 parent 69172d2 commit e747f5e

File tree

3 files changed

+61
-33
lines changed

3 files changed

+61
-33
lines changed

speech/grpc/pom.xml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<!--
2+
Copyright 2016 Google Inc. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<project>
417
<modelVersion>4.0.0</modelVersion>
518

619
<groupId>com.google.cloud.speech</groupId>
@@ -25,6 +38,13 @@
2538
<url>http://www.google.com</url>
2639
</organization>
2740

41+
<parent>
42+
<groupId>com.google.cloud</groupId>
43+
<artifactId>doc-samples</artifactId>
44+
<version>1.0.0</version>
45+
<relativePath>../..</relativePath>
46+
</parent>
47+
2848
<properties>
2949
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3050
</properties>

speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/NonStreamingRecognizeClient.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,41 @@
3434
import com.google.cloud.speech.v1.SpeechGrpc;
3535
import com.google.protobuf.ByteString;
3636
import com.google.protobuf.TextFormat;
37+
3738
import io.grpc.ManagedChannel;
3839
import io.grpc.StatusRuntimeException;
3940
import io.grpc.auth.ClientAuthInterceptor;
4041
import io.grpc.netty.NegotiationType;
4142
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+
4251
import java.io.IOException;
4352
import java.nio.file.Files;
4453
import java.nio.file.Path;
4554
import java.nio.file.Paths;
4655
import java.util.Arrays;
4756
import java.util.List;
48-
import java.util.concurrent.CountDownLatch;
4957
import java.util.concurrent.Executors;
5058
import java.util.concurrent.TimeUnit;
5159
import java.util.logging.Level;
5260
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;
5961

6062
/**
6163
* Client that sends audio to Speech.NonStreamingRecognize and returns transcript.
6264
*/
6365
public class NonStreamingRecognizeClient {
6466

6567
private static final Logger logger =
66-
Logger.getLogger(NonStreamingRecognizeClient.class.getName());
68+
Logger.getLogger(NonStreamingRecognizeClient.class.getName());
6769

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");
7072

7173
private final String host;
7274
private final int port;
@@ -76,8 +78,11 @@ public class NonStreamingRecognizeClient {
7678
private final ManagedChannel channel;
7779
private final SpeechGrpc.SpeechBlockingStub blockingStub;
7880

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 {
8186
this.host = host;
8287
this.port = port;
8388
this.file = file;
@@ -134,7 +139,7 @@ public void recognize() {
134139

135140
public static void main(String[] args) throws Exception {
136141

137-
String audio_file = "";
142+
String audioFile = "";
138143
String host = "speech.googleapis.com";
139144
Integer port = 443;
140145
Integer sampling = 16000;
@@ -166,7 +171,7 @@ public static void main(String[] args) throws Exception {
166171
try {
167172
CommandLine line = parser.parse(options, args);
168173
if (line.hasOption("file")) {
169-
audio_file = line.getOptionValue("file");
174+
audioFile = line.getOptionValue("file");
170175
} else {
171176
System.err.println("An Audio file path must be specified (e.g. /foo/baz.raw).");
172177
System.exit(1);
@@ -192,14 +197,13 @@ public static void main(String[] args) throws Exception {
192197
System.err.println("An Audio sampling rate must be specified.");
193198
System.exit(1);
194199
}
195-
}
196-
catch (ParseException exp) {
200+
} catch (ParseException exp) {
197201
System.err.println("Unexpected exception:" + exp.getMessage());
198202
System.exit(1);
199203
}
200204

201205
NonStreamingRecognizeClient client =
202-
new NonStreamingRecognizeClient(host, port, audio_file, sampling);
206+
new NonStreamingRecognizeClient(host, port, audioFile, sampling);
203207
try {
204208
client.recognize();
205209
} finally {

speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/RecognizeClient.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,21 @@
3434
import com.google.cloud.speech.v1.SpeechGrpc;
3535
import com.google.protobuf.ByteString;
3636
import com.google.protobuf.TextFormat;
37+
3738
import io.grpc.ManagedChannel;
3839
import io.grpc.Status;
3940
import io.grpc.auth.ClientAuthInterceptor;
4041
import io.grpc.netty.NegotiationType;
4142
import io.grpc.netty.NettyChannelBuilder;
4243
import io.grpc.stub.StreamObserver;
44+
45+
import org.apache.commons.cli.CommandLine;
46+
import org.apache.commons.cli.CommandLineParser;
47+
import org.apache.commons.cli.DefaultParser;
48+
import org.apache.commons.cli.OptionBuilder;
49+
import org.apache.commons.cli.Options;
50+
import org.apache.commons.cli.ParseException;
51+
4352
import java.io.File;
4453
import java.io.FileInputStream;
4554
import java.io.IOException;
@@ -50,13 +59,6 @@
5059
import java.util.concurrent.TimeUnit;
5160
import java.util.logging.Level;
5261
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-
6062

6163
/**
6264
* Client that sends streaming audio to Speech.Recognize and returns streaming transcript.
@@ -78,7 +80,9 @@ public class RecognizeClient {
7880
private static final List<String> OAUTH2_SCOPES =
7981
Arrays.asList("https://www.googleapis.com/auth/xapi.zoo");
8082

81-
/** Construct client connecting to Cloud Speech server at {@code host:port}. */
83+
/**
84+
* Construct client connecting to Cloud Speech server at {@code host:port}.
85+
*/
8286
public RecognizeClient(String host, int port, String file, int samplingRate) throws IOException {
8387
this.host = host;
8488
this.port = port;
@@ -109,8 +113,8 @@ public void onNext(RecognizeResponse response) {
109113
}
110114

111115
@Override
112-
public void onError(Throwable t) {
113-
Status status = Status.fromThrowable(t);
116+
public void onError(Throwable error) {
117+
Status status = Status.fromThrowable(error);
114118
logger.log(Level.WARNING, "recognize failed: {0}", status);
115119
finishLatch.countDown();
116120
}
@@ -169,7 +173,7 @@ public void onCompleted() {
169173

170174
public static void main(String[] args) throws Exception {
171175

172-
String audio_file = "";
176+
String audioFile = "";
173177
String host = "speech.googleapis.com";
174178
Integer port = 443;
175179
Integer sampling = 16000;
@@ -201,7 +205,7 @@ public static void main(String[] args) throws Exception {
201205
try {
202206
CommandLine line = parser.parse(options, args);
203207
if (line.hasOption("file")) {
204-
audio_file = line.getOptionValue("file");
208+
audioFile = line.getOptionValue("file");
205209
} else {
206210
System.err.println("An Audio file must be specified (e.g. /foo/baz.raw).");
207211
System.exit(1);
@@ -233,7 +237,7 @@ public static void main(String[] args) throws Exception {
233237
}
234238

235239
RecognizeClient client =
236-
new RecognizeClient(host, port, audio_file, sampling);
240+
new RecognizeClient(host, port, audioFile, sampling);
237241
try {
238242
client.recognize();
239243
} finally {

0 commit comments

Comments
 (0)