From e747f5ec29e360a2ef9f0f3bec4cecd1e51258db Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Mon, 21 Mar 2016 17:33:42 -0700 Subject: [PATCH] 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 --- speech/grpc/pom.xml | 26 +++++++++++-- .../demos/NonStreamingRecognizeClient.java | 38 ++++++++++--------- .../speech/grpc/demos/RecognizeClient.java | 30 ++++++++------- 3 files changed, 61 insertions(+), 33 deletions(-) diff --git a/speech/grpc/pom.xml b/speech/grpc/pom.xml index 607a68a8ad5..c1853902515 100644 --- a/speech/grpc/pom.xml +++ b/speech/grpc/pom.xml @@ -1,6 +1,19 @@ - + + 4.0.0 com.google.cloud.speech @@ -25,6 +38,13 @@ http://www.google.com + + com.google.cloud + doc-samples + 1.0.0 + ../.. + + UTF-8 diff --git a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/NonStreamingRecognizeClient.java b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/NonStreamingRecognizeClient.java index 04823c92256..3e413a71fa3 100644 --- a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/NonStreamingRecognizeClient.java +++ b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/NonStreamingRecognizeClient.java @@ -34,28 +34,30 @@ import com.google.cloud.speech.v1.SpeechGrpc; import com.google.protobuf.ByteString; import com.google.protobuf.TextFormat; + import io.grpc.ManagedChannel; import io.grpc.StatusRuntimeException; import io.grpc.auth.ClientAuthInterceptor; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.List; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.OptionBuilder; -import org.apache.commons.cli.ParseException; /** * Client that sends audio to Speech.NonStreamingRecognize and returns transcript. @@ -63,10 +65,10 @@ public class NonStreamingRecognizeClient { private static final Logger logger = - Logger.getLogger(NonStreamingRecognizeClient.class.getName()); + Logger.getLogger(NonStreamingRecognizeClient.class.getName()); - private static final List OAUTH2_SCOPES = - Arrays.asList("https://www.googleapis.com/auth/xapi.zoo"); + private static final List OAUTH2_SCOPES = + Arrays.asList("https://www.googleapis.com/auth/xapi.zoo"); private final String host; private final int port; @@ -76,8 +78,11 @@ public class NonStreamingRecognizeClient { private final ManagedChannel channel; private final SpeechGrpc.SpeechBlockingStub blockingStub; - /** Construct client connecting to Cloud Speech server at {@code host:port}. */ - public NonStreamingRecognizeClient(String host, int port, String file, int samplingRate) throws IOException { + /** + * Construct client connecting to Cloud Speech server at {@code host:port}. + */ + public NonStreamingRecognizeClient(String host, int port, String file, int samplingRate) + throws IOException { this.host = host; this.port = port; this.file = file; @@ -134,7 +139,7 @@ public void recognize() { public static void main(String[] args) throws Exception { - String audio_file = ""; + String audioFile = ""; String host = "speech.googleapis.com"; Integer port = 443; Integer sampling = 16000; @@ -166,7 +171,7 @@ public static void main(String[] args) throws Exception { try { CommandLine line = parser.parse(options, args); if (line.hasOption("file")) { - audio_file = line.getOptionValue("file"); + audioFile = line.getOptionValue("file"); } else { System.err.println("An Audio file path must be specified (e.g. /foo/baz.raw)."); System.exit(1); @@ -192,14 +197,13 @@ public static void main(String[] args) throws Exception { System.err.println("An Audio sampling rate must be specified."); System.exit(1); } - } - catch (ParseException exp) { + } catch (ParseException exp) { System.err.println("Unexpected exception:" + exp.getMessage()); System.exit(1); } NonStreamingRecognizeClient client = - new NonStreamingRecognizeClient(host, port, audio_file, sampling); + new NonStreamingRecognizeClient(host, port, audioFile, sampling); try { client.recognize(); } finally { diff --git a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/RecognizeClient.java b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/RecognizeClient.java index 223db38bba6..e6cd8dd737b 100644 --- a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/RecognizeClient.java +++ b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/RecognizeClient.java @@ -34,12 +34,21 @@ import com.google.cloud.speech.v1.SpeechGrpc; import com.google.protobuf.ByteString; import com.google.protobuf.TextFormat; + import io.grpc.ManagedChannel; import io.grpc.Status; import io.grpc.auth.ClientAuthInterceptor; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; import io.grpc.stub.StreamObserver; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -50,13 +59,6 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.OptionBuilder; -import org.apache.commons.cli.ParseException; - /** * Client that sends streaming audio to Speech.Recognize and returns streaming transcript. @@ -78,7 +80,9 @@ public class RecognizeClient { private static final List OAUTH2_SCOPES = Arrays.asList("https://www.googleapis.com/auth/xapi.zoo"); - /** Construct client connecting to Cloud Speech server at {@code host:port}. */ + /** + * Construct client connecting to Cloud Speech server at {@code host:port}. + */ public RecognizeClient(String host, int port, String file, int samplingRate) throws IOException { this.host = host; this.port = port; @@ -109,8 +113,8 @@ public void onNext(RecognizeResponse response) { } @Override - public void onError(Throwable t) { - Status status = Status.fromThrowable(t); + public void onError(Throwable error) { + Status status = Status.fromThrowable(error); logger.log(Level.WARNING, "recognize failed: {0}", status); finishLatch.countDown(); } @@ -169,7 +173,7 @@ public void onCompleted() { public static void main(String[] args) throws Exception { - String audio_file = ""; + String audioFile = ""; String host = "speech.googleapis.com"; Integer port = 443; Integer sampling = 16000; @@ -201,7 +205,7 @@ public static void main(String[] args) throws Exception { try { CommandLine line = parser.parse(options, args); if (line.hasOption("file")) { - audio_file = line.getOptionValue("file"); + audioFile = line.getOptionValue("file"); } else { System.err.println("An Audio file must be specified (e.g. /foo/baz.raw)."); System.exit(1); @@ -233,7 +237,7 @@ public static void main(String[] args) throws Exception { } RecognizeClient client = - new RecognizeClient(host, port, audio_file, sampling); + new RecognizeClient(host, port, audioFile, sampling); try { client.recognize(); } finally {