From aaf5e91220e47eb1c567adea48d819924d5610e0 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Fri, 27 May 2016 00:30:40 -0700 Subject: [PATCH 01/20] added gcs read for audio file --- speech/grpc/pom.xml | 5 ++ .../grpc/demos/AudioRequestFactory.java | 78 +++++++++++++++++++ .../demos/NonStreamingRecognizeClient.java | 28 ++++--- 3 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java diff --git a/speech/grpc/pom.xml b/speech/grpc/pom.xml index c1853902515..b8a8b8a37d0 100644 --- a/speech/grpc/pom.xml +++ b/speech/grpc/pom.xml @@ -111,6 +111,11 @@ limitations under the License. + + com.google.cloud + gcloud-java + 0.2.2 + commons-cli commons-cli diff --git a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java new file mode 100644 index 00000000000..36b6e34a8b5 --- /dev/null +++ b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java @@ -0,0 +1,78 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// AudioRequestFactory takes a URI as an input and creates an AudioRequest +// The factory takes as input files of type local and gs + +package com.google.cloud.speech.grpc.demos; + +import com.google.cloud.speech.v1.AudioRequest; +import java.net.URI; +import java.io.IOException; + +import com.google.cloud.storage.Blob; +import com.google.cloud.storage.BlobId; +import com.google.cloud.storage.Storage; +import com.google.cloud.storage.StorageOptions; +import com.google.protobuf.ByteString; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class AudioRequestFactory { + + private static final String FILE = "file"; + private static final String GS = "gs"; + + /** + * Takes an input URI of form $scheme:// and converts to audio request + * + * @param uri input uri + * @return AudioRequest audio request + */ + public static AudioRequest createRequest(URI uri) + throws IOException { + if(uri.getScheme() == null || uri.getScheme().equals(FILE)) { + Path path = Paths.get(uri); + return audioFromBytes(Files.readAllBytes(path)); + } + else if(uri.getScheme().equals(GS)) { + Storage storage = StorageOptions.defaultInstance().service(); + String path = uri.getPath(); + BlobId blobId = BlobId.of(uri.getHost(), path.substring(1,path.length())); + Blob blob = storage.get(blobId); + return audioFromBytes(blob.content()); + } + throw new RuntimeException("scheme not supported "+uri.getScheme()); + } + + /** + * Convert bytes to AudioRequest + * + * @param bytes input bytes + * @return AudioRequest audio request + */ + private static AudioRequest audioFromBytes(byte[] bytes) { + return AudioRequest.newBuilder() + .setContent(ByteString.copyFrom(bytes)) + .build(); + } + + public static void main(String[] args) { + + } +} 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 d7b7d70af08..2eadaaa1f39 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 @@ -48,6 +48,7 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; +import java.net.URI; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -72,7 +73,7 @@ public class NonStreamingRecognizeClient { private final String host; private final int port; - private final String file; + private final URI input; private final int samplingRate; private final ManagedChannel channel; @@ -81,11 +82,11 @@ public class NonStreamingRecognizeClient { /** * Construct client connecting to Cloud Speech server at {@code host:port}. */ - public NonStreamingRecognizeClient(String host, int port, String file, int samplingRate) + public NonStreamingRecognizeClient(String host, int port, URI input, int samplingRate) throws IOException { this.host = host; this.port = port; - this.file = file; + this.input = input; this.samplingRate = samplingRate; GoogleCredentials creds = GoogleCredentials.getApplicationDefault(); @@ -99,10 +100,7 @@ public NonStreamingRecognizeClient(String host, int port, String file, int sampl } private AudioRequest createAudioRequest() throws IOException { - Path path = Paths.get(file); - return AudioRequest.newBuilder() - .setContent(ByteString.copyFrom(Files.readAllBytes(path))) - .build(); + return AudioRequestFactory.createRequest(this.input); } public void shutdown() throws InterruptedException { @@ -115,10 +113,10 @@ public void recognize() { try { audio = createAudioRequest(); } catch (IOException e) { - logger.log(Level.WARNING, "Failed to read audio file: " + file); + logger.log(Level.WARNING, "Failed to read audio uri input: " + input); return; } - logger.info("Sending " + audio.getContent().size() + " bytes from audio file: " + file); + logger.info("Sending " + audio.getContent().size() + " bytes from audio uri input: " + input); InitialRecognizeRequest initial = InitialRecognizeRequest.newBuilder() .setEncoding(AudioEncoding.LINEAR16) .setSampleRate(samplingRate) @@ -147,8 +145,8 @@ public static void main(String[] args) throws Exception { CommandLineParser parser = new DefaultParser(); Options options = new Options(); - options.addOption(OptionBuilder.withLongOpt("file") - .withDescription("path to audio file") + options.addOption(OptionBuilder.withLongOpt("uri") + .withDescription("path to audio uri") .hasArg() .withArgName("FILE_PATH") .create()); @@ -170,10 +168,10 @@ public static void main(String[] args) throws Exception { try { CommandLine line = parser.parse(options, args); - if (line.hasOption("file")) { - audioFile = line.getOptionValue("file"); + if (line.hasOption("uri")) { + audioFile = line.getOptionValue("uri"); } else { - System.err.println("An Audio file path must be specified (e.g. /foo/baz.raw)."); + System.err.println("An Audio uri must be specified (e.g. file://foo/baz.raw)."); System.exit(1); } @@ -203,7 +201,7 @@ public static void main(String[] args) throws Exception { } NonStreamingRecognizeClient client = - new NonStreamingRecognizeClient(host, port, audioFile, sampling); + new NonStreamingRecognizeClient(host, port, URI.create(audioFile), sampling); try { client.recognize(); } finally { From e81f5380462f63329963eecb9cc647149491b7a8 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Fri, 27 May 2016 00:35:42 -0700 Subject: [PATCH 02/20] added gcs read for audio file --- .../cloud/speech/grpc/demos/NonStreamingRecognizeClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2eadaaa1f39..4187d4321f0 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 @@ -171,7 +171,7 @@ public static void main(String[] args) throws Exception { if (line.hasOption("uri")) { audioFile = line.getOptionValue("uri"); } else { - System.err.println("An Audio uri must be specified (e.g. file://foo/baz.raw)."); + System.err.println("An Audio uri must be specified (e.g. file:///foo/baz.raw)."); System.exit(1); } From ed37b39075890e94e88afa4a289daa81f80811ac Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Fri, 27 May 2016 00:50:34 -0700 Subject: [PATCH 03/20] removed main --- .../google/cloud/speech/grpc/demos/AudioRequestFactory.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java index 36b6e34a8b5..9bdf7e6657a 100644 --- a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java +++ b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java @@ -71,8 +71,4 @@ private static AudioRequest audioFromBytes(byte[] bytes) { .setContent(ByteString.copyFrom(bytes)) .build(); } - - public static void main(String[] args) { - - } } From e84a183eb0be6834d130d010cab67bf6ca229fdb Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Fri, 27 May 2016 09:20:51 -0700 Subject: [PATCH 04/20] added comment to class javadoc --- .../google/cloud/speech/grpc/demos/AudioRequestFactory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java index 9bdf7e6657a..5faee89afff 100644 --- a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java +++ b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java @@ -14,8 +14,6 @@ * limitations under the License. */ -// AudioRequestFactory takes a URI as an input and creates an AudioRequest -// The factory takes as input files of type local and gs package com.google.cloud.speech.grpc.demos; @@ -33,6 +31,10 @@ import java.nio.file.Path; import java.nio.file.Paths; +/* + * AudioRequestFactory takes a URI as an input and creates an AudioRequest. The URI can point to a + * local file or a file on google cloud storage. + */ public class AudioRequestFactory { private static final String FILE = "file"; From aef1f1eff921a20531ee15ef757af3d333ec65ea Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Fri, 27 May 2016 09:39:41 -0700 Subject: [PATCH 05/20] fixed style issues --- .../speech/grpc/demos/AudioRequestFactory.java | 17 ++++++++--------- .../grpc/demos/NonStreamingRecognizeClient.java | 6 +----- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java index 5faee89afff..4149bfacef1 100644 --- a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java +++ b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java @@ -18,15 +18,15 @@ package com.google.cloud.speech.grpc.demos; import com.google.cloud.speech.v1.AudioRequest; -import java.net.URI; -import java.io.IOException; - import com.google.cloud.storage.Blob; import com.google.cloud.storage.BlobId; import com.google.cloud.storage.Storage; import com.google.cloud.storage.StorageOptions; import com.google.protobuf.ByteString; +import java.io.IOException; + +import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -41,29 +41,28 @@ public class AudioRequestFactory { private static final String GS = "gs"; /** - * Takes an input URI of form $scheme:// and converts to audio request + * Takes an input URI of form $scheme:// and converts to audio request. * * @param uri input uri * @return AudioRequest audio request */ public static AudioRequest createRequest(URI uri) throws IOException { - if(uri.getScheme() == null || uri.getScheme().equals(FILE)) { + if (uri.getScheme() == null || uri.getScheme().equals(FILE)) { Path path = Paths.get(uri); return audioFromBytes(Files.readAllBytes(path)); - } - else if(uri.getScheme().equals(GS)) { + } else if (uri.getScheme().equals(GS)) { Storage storage = StorageOptions.defaultInstance().service(); String path = uri.getPath(); BlobId blobId = BlobId.of(uri.getHost(), path.substring(1,path.length())); Blob blob = storage.get(blobId); return audioFromBytes(blob.content()); } - throw new RuntimeException("scheme not supported "+uri.getScheme()); + throw new RuntimeException("scheme not supported " + uri.getScheme()); } /** - * Convert bytes to AudioRequest + * Convert bytes to AudioRequest. * * @param bytes input bytes * @return AudioRequest audio request 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 4187d4321f0..3952c7f0e5a 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 @@ -32,7 +32,6 @@ import com.google.cloud.speech.v1.NonStreamingRecognizeResponse; import com.google.cloud.speech.v1.RecognizeRequest; import com.google.cloud.speech.v1.SpeechGrpc; -import com.google.protobuf.ByteString; import com.google.protobuf.TextFormat; import io.grpc.ManagedChannel; @@ -48,11 +47,8 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -import java.net.URI; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.net.URI; import java.util.Arrays; import java.util.List; import java.util.concurrent.Executors; From ef82a90067feaa18baae15ef0ca0a14d1d612d28 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Fri, 27 May 2016 10:14:25 -0700 Subject: [PATCH 06/20] casing of GCS --- .../com/google/cloud/speech/grpc/demos/AudioRequestFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java index 4149bfacef1..9ca3c657d31 100644 --- a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java +++ b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java @@ -33,7 +33,7 @@ /* * AudioRequestFactory takes a URI as an input and creates an AudioRequest. The URI can point to a - * local file or a file on google cloud storage. + * local file or a file on Google Cloud Storage. */ public class AudioRequestFactory { From ca7cb9e39987271b543f71869791baec80108459 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Fri, 27 May 2016 10:15:14 -0700 Subject: [PATCH 07/20] missing space --- .../com/google/cloud/speech/grpc/demos/AudioRequestFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java index 9ca3c657d31..3b917c6c1b3 100644 --- a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java +++ b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java @@ -54,7 +54,7 @@ public static AudioRequest createRequest(URI uri) } else if (uri.getScheme().equals(GS)) { Storage storage = StorageOptions.defaultInstance().service(); String path = uri.getPath(); - BlobId blobId = BlobId.of(uri.getHost(), path.substring(1,path.length())); + BlobId blobId = BlobId.of(uri.getHost(), path.substring(1, path.length())); Blob blob = storage.get(blobId); return audioFromBytes(blob.content()); } From c1f92acf9937fc9b92b3d8a55710f4e2e3d92879 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Sun, 29 May 2016 01:07:11 -0700 Subject: [PATCH 08/20] added uri read direct --- .../grpc/demos/AudioRequestFactory.java | 19 ++----- .../proto/google/speech/v1/cloud-speech.proto | 53 +++++++++++++++---- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java index 3b917c6c1b3..fce35b3099c 100644 --- a/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java +++ b/speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AudioRequestFactory.java @@ -18,14 +18,9 @@ package com.google.cloud.speech.grpc.demos; import com.google.cloud.speech.v1.AudioRequest; -import com.google.cloud.storage.Blob; -import com.google.cloud.storage.BlobId; -import com.google.cloud.storage.Storage; -import com.google.cloud.storage.StorageOptions; import com.google.protobuf.ByteString; import java.io.IOException; - import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; @@ -37,8 +32,8 @@ */ public class AudioRequestFactory { - private static final String FILE = "file"; - private static final String GS = "gs"; + private static final String FILE_SCHEME = "file"; + private static final String GS_SCHEME = "gs"; /** * Takes an input URI of form $scheme:// and converts to audio request. @@ -48,15 +43,11 @@ public class AudioRequestFactory { */ public static AudioRequest createRequest(URI uri) throws IOException { - if (uri.getScheme() == null || uri.getScheme().equals(FILE)) { + if (uri.getScheme() == null || uri.getScheme().equals(FILE_SCHEME)) { Path path = Paths.get(uri); return audioFromBytes(Files.readAllBytes(path)); - } else if (uri.getScheme().equals(GS)) { - Storage storage = StorageOptions.defaultInstance().service(); - String path = uri.getPath(); - BlobId blobId = BlobId.of(uri.getHost(), path.substring(1, path.length())); - Blob blob = storage.get(blobId); - return audioFromBytes(blob.content()); + } else if (uri.getScheme().equals(GS_SCHEME)) { + return AudioRequest.newBuilder().setUri(uri.toString()).build(); } throw new RuntimeException("scheme not supported " + uri.getScheme()); } diff --git a/speech/grpc/src/main/proto/google/speech/v1/cloud-speech.proto b/speech/grpc/src/main/proto/google/speech/v1/cloud-speech.proto index 6ee3b031552..97dd8629649 100644 --- a/speech/grpc/src/main/proto/google/speech/v1/cloud-speech.proto +++ b/speech/grpc/src/main/proto/google/speech/v1/cloud-speech.proto @@ -23,6 +23,7 @@ option java_multiple_files = true; option java_outer_classname = "SpeechProto"; option java_package = "com.google.cloud.speech.v1"; + // Service that implements Google Cloud Speech API. service Speech { // Perform bidirectional streaming speech recognition on audio using gRPC. @@ -30,7 +31,7 @@ service Speech { // Perform non-streaming speech recognition on audio using HTTPS. rpc NonStreamingRecognize(RecognizeRequest) returns (NonStreamingRecognizeResponse) { - option (.google.api.http) = { post: "/v1/speech:recognize" body: "*" }; + option (google.api.http) = { post: "/v1/speech:recognize" body: "*" }; } } @@ -54,7 +55,7 @@ message RecognizeRequest { // The audio data to be recognized. For `NonStreamingRecognize`, all the // audio data must be contained in the first (and only) `RecognizeRequest` - // message. For streaming `Recognize`, sequential chunks of audio data are + // message. For streaming `Recognize`, sequential chunks of audio data are // sent in sequential `RecognizeRequest` messages. AudioRequest audio_request = 2; } @@ -64,7 +65,7 @@ message RecognizeRequest { message InitialRecognizeRequest { // Audio encoding of the data sent in the audio message. enum AudioEncoding { - // Not specified. Will return result `INVALID_ARGUMENT`. + // Not specified. Will return result [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]. ENCODING_UNSPECIFIED = 0; // Uncompressed 16-bit signed little-endian samples. @@ -118,8 +119,6 @@ message InitialRecognizeRequest { // profanities, replacing all but the initial character in each filtered word // with asterisks, e.g. "f***". If set to `false` or omitted, profanities // won't be filtered out. - // Note that profanity filtering is not implemented for all languages. - // If the language is not supported, this setting has no effect. bool profanity_filter = 5; // [Optional] If `false` or omitted, the recognizer will detect a single @@ -146,13 +145,38 @@ message InitialRecognizeRequest { // as they become available. // If `false` or omitted, no `EndpointerEvents` are returned. bool enable_endpointer_events = 8; + + // [Optional] URI that points to a file where the recognition result should + // be stored in JSON format. If omitted or empty string, the recognition + // result is returned in the response. Should be specified only for + // `NonStreamingRecognize`. If specified in a `Recognize` request, + // `Recognize` returns [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]. + // If specified in a `NonStreamingRecognize` request, + // `NonStreamingRecognize` returns immediately, and the output file + // is created asynchronously once the audio processing completes. + // Currently, only Google Cloud Storage URIs are supported, which must be + // specified in the following format: `gs://bucket_name/object_name` + // (other URI formats return [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]). For + // more information, see [Request URIs](/storage/docs/reference-uris). + string output_uri = 9; } // Contains audio data in the format specified in the `InitialRecognizeRequest`. +// Either `content` or `uri` must be supplied. Supplying both or neither +// returns [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]. message AudioRequest { - // [Required] The audio data bytes encoded as specified in - // `InitialRecognizeRequest`. + // The audio data bytes encoded as specified in + // `InitialRecognizeRequest`. Note: as with all bytes fields, protobuffers + // use a pure binary representation, whereas JSON representations use base64. bytes content = 1; + + // URI that points to a file that contains audio data bytes as specified in + // `InitialRecognizeRequest`. Currently, only Google Cloud Storage URIs are + // supported, which must be specified in the following format: + // `gs://bucket_name/object_name` (other URI formats return + // [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]). For more information, see + // [Request URIs](/storage/docs/reference-uris). + string uri = 2; } // `NonStreamingRecognizeResponse` is the only message returned to the client by @@ -191,10 +215,14 @@ message RecognizeResponse { // [Output-only] If set, returns a [google.rpc.Status][] message that // specifies the error for the operation. - .google.rpc.Status error = 1; - - // [Output-only] May contain zero or one `is_final=true` result (the newly - // settled portion). May also contain zero or more `is_final=false` results. + google.rpc.Status error = 1; + + // [Output-only] For `continuous=false`, this repeated list contains zero or + // one result that corresponds to all of the audio processed so far. For + // `continuous=true`, this repeated list contains zero or more results that + // correspond to consecutive portions of the audio being processed. + // In both cases, contains zero or one `is_final=true` result (the newly + // settled portion), followed by zero or more `is_final=false` results. repeated SpeechRecognitionResult results = 2; // [Output-only] Indicates the lowest index in the `results` array that has @@ -206,7 +234,10 @@ message RecognizeResponse { EndpointerEvent endpoint = 4; } +// A speech recognition result corresponding to a portion of the audio. message SpeechRecognitionResult { + // [Output-only] May contain one or more recognition hypotheses (up to the + // maximum specified in `max_alternatives`). repeated SpeechRecognitionAlternative alternatives = 1; // [Output-only] Set `true` if this is the final time the speech service will From 00f367a14cd2409bd7a90e8dde6fa6d3f88f5792 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Sun, 29 May 2016 01:08:13 -0700 Subject: [PATCH 09/20] removed gcloud --- speech/grpc/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/speech/grpc/pom.xml b/speech/grpc/pom.xml index b8a8b8a37d0..c1853902515 100644 --- a/speech/grpc/pom.xml +++ b/speech/grpc/pom.xml @@ -111,11 +111,6 @@ limitations under the License. - - com.google.cloud - gcloud-java - 0.2.2 - commons-cli commons-cli From 80517281c2a7fe4f26f70060acbfec8af7d38b9a Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 30 May 2016 21:07:51 -0700 Subject: [PATCH 10/20] added test file --- speech/grpc/pom.xml | 6 ++ .../grpc/demos/AudioRequestFactoryTest.java | 60 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java diff --git a/speech/grpc/pom.xml b/speech/grpc/pom.xml index c1853902515..b11b1972ba1 100644 --- a/speech/grpc/pom.xml +++ b/speech/grpc/pom.xml @@ -111,6 +111,12 @@ limitations under the License. + + junit + junit + 4.12 + test + commons-cli commons-cli diff --git a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java new file mode 100644 index 00000000000..59af1e10f1b --- /dev/null +++ b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java @@ -0,0 +1,60 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.speech.grpc.demos; + +import com.google.cloud.speech.v1.AudioRequest; +import static org.junit.Assert.assertSame; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.IOException; +import java.net.URI; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +/** + * Unit tests for {@link AudioRequestFactory}. + */ +@RunWith(JUnit4.class) +public class AudioRequestFactoryTest { + + @Test + public void verifyBytesInSizeFromLocalFile() throws IOException { + URI uri = new File("speech/grpc/resources/audio.raw").toURI(); + AudioRequest audio = AudioRequestFactory.createRequest(uri); + + int numBytes = audio.getContent().toByteArray().length(); + + //assert the number of bytes in the audio as 57958 + assertSame(numBytes, 57958); + } + + @Test + public void verifyBytesInSizeFromGoogleStorageFile() throws IOException { + URI uri = URI.create("gs://cloud-samples-test/speech/audio.raw"); + AudioRequest audio = AudioRequestFactory.createRequest(uri); + + int numBytes = audio.getContent().toByteArray().length(); + + //assert the number of bytes in the audio as 57958 + assertSame(numBytes, 57958); + } +} From 9ccfdf141d4638d7f5092d92a71ea911fad274a8 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 30 May 2016 21:16:09 -0700 Subject: [PATCH 11/20] added test --- .../grpc/demos/AudioRequestFactoryTest.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java index 59af1e10f1b..40850b2e660 100644 --- a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java +++ b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java @@ -17,18 +17,16 @@ package com.google.cloud.speech.grpc.demos; import com.google.cloud.speech.v1.AudioRequest; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import java.io.File; import java.io.IOException; import java.net.URI; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; /** * Unit tests for {@link AudioRequestFactory}. @@ -38,13 +36,13 @@ public class AudioRequestFactoryTest { @Test public void verifyBytesInSizeFromLocalFile() throws IOException { - URI uri = new File("speech/grpc/resources/audio.raw").toURI(); + URI uri = new File("resources/audio.raw").toURI(); AudioRequest audio = AudioRequestFactory.createRequest(uri); - int numBytes = audio.getContent().toByteArray().length(); + int numBytes = audio.getContent().toByteArray().length; //assert the number of bytes in the audio as 57958 - assertSame(numBytes, 57958); + assertEquals(numBytes, 57958); } @Test @@ -52,9 +50,9 @@ public void verifyBytesInSizeFromGoogleStorageFile() throws IOException { URI uri = URI.create("gs://cloud-samples-test/speech/audio.raw"); AudioRequest audio = AudioRequestFactory.createRequest(uri); - int numBytes = audio.getContent().toByteArray().length(); + int numBytes = audio.getContent().toByteArray().length; //assert the number of bytes in the audio as 57958 - assertSame(numBytes, 57958); + assertEquals(numBytes, 57958); } } From 7b925313306a0bd441516f640275aaf3c5f58cae Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 30 May 2016 21:27:49 -0700 Subject: [PATCH 12/20] added test --- .../cloud/speech/grpc/demos/AudioRequestFactoryTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java index 40850b2e660..8afac40629e 100644 --- a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java +++ b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java @@ -42,7 +42,7 @@ public void verifyBytesInSizeFromLocalFile() throws IOException { int numBytes = audio.getContent().toByteArray().length; //assert the number of bytes in the audio as 57958 - assertEquals(numBytes, 57958); + assertEquals(57958, numBytes); } @Test @@ -53,6 +53,6 @@ public void verifyBytesInSizeFromGoogleStorageFile() throws IOException { int numBytes = audio.getContent().toByteArray().length; //assert the number of bytes in the audio as 57958 - assertEquals(numBytes, 57958); + assertEquals(57958, numBytes); } } From 8e01d28ecadb3d62db4efe8cde116fbbaccc2e67 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 30 May 2016 22:21:47 -0700 Subject: [PATCH 13/20] added test --- .../google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java index 8afac40629e..db6eb25f520 100644 --- a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java +++ b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java @@ -47,7 +47,7 @@ public void verifyBytesInSizeFromLocalFile() throws IOException { @Test public void verifyBytesInSizeFromGoogleStorageFile() throws IOException { - URI uri = URI.create("gs://cloud-samples-test/speech/audio.raw"); + URI uri = URI.create("gs://cloud-samples-tests/speech/audio.raw"); AudioRequest audio = AudioRequestFactory.createRequest(uri); int numBytes = audio.getContent().toByteArray().length; From edbc8155c53a672cd3532b1a8cfd1350043fdd92 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 30 May 2016 22:32:58 -0700 Subject: [PATCH 14/20] removed junit --- speech/grpc/pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/speech/grpc/pom.xml b/speech/grpc/pom.xml index b11b1972ba1..09b35b998f4 100644 --- a/speech/grpc/pom.xml +++ b/speech/grpc/pom.xml @@ -110,13 +110,6 @@ limitations under the License. - - - junit - junit - 4.12 - test - commons-cli commons-cli From cecea6c0a3eb863d8b2bfa0cd5b8b42639de89f3 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Mon, 30 May 2016 22:35:07 -0700 Subject: [PATCH 15/20] removed junit --- speech/grpc/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/speech/grpc/pom.xml b/speech/grpc/pom.xml index 09b35b998f4..c1853902515 100644 --- a/speech/grpc/pom.xml +++ b/speech/grpc/pom.xml @@ -110,6 +110,7 @@ limitations under the License. + commons-cli commons-cli From 4605479c0b00dbf11a8be69937af75983b6efa7f Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Tue, 31 May 2016 07:56:43 -0700 Subject: [PATCH 16/20] assert uri --- .../cloud/speech/grpc/demos/AudioRequestFactoryTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java index db6eb25f520..c72c2b07d8d 100644 --- a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java +++ b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java @@ -47,12 +47,17 @@ public void verifyBytesInSizeFromLocalFile() throws IOException { @Test public void verifyBytesInSizeFromGoogleStorageFile() throws IOException { - URI uri = URI.create("gs://cloud-samples-tests/speech/audio.raw"); + String audioUri = "gs://cloud-samples-tests/speech/audio.raw"; + + URI uri = URI.create(audioUri); AudioRequest audio = AudioRequestFactory.createRequest(uri); int numBytes = audio.getContent().toByteArray().length; //assert the number of bytes in the audio as 57958 - assertEquals(57958, numBytes); + assertEquals(0, numBytes); + + //assert the uri + assertEquals(audioUri, audio.getUri()); } } From 3ba3ea0dde97eaf47d1c99fce664c84dcaeb248b Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Tue, 31 May 2016 08:24:40 -0700 Subject: [PATCH 17/20] committed junit --- speech/grpc/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/speech/grpc/pom.xml b/speech/grpc/pom.xml index c1853902515..6b4376039cb 100644 --- a/speech/grpc/pom.xml +++ b/speech/grpc/pom.xml @@ -111,6 +111,12 @@ limitations under the License. + + junit + junit + 4.12 + test + commons-cli commons-cli From 6a9f60e13d597239e89baed105ef138d8ba40734 Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Tue, 31 May 2016 08:46:36 -0700 Subject: [PATCH 18/20] removed Before import --- .../google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java index c72c2b07d8d..232ff9d5a0d 100644 --- a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java +++ b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java @@ -19,7 +19,6 @@ import com.google.cloud.speech.v1.AudioRequest; import static org.junit.Assert.assertEquals; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; From c73f642915024434c457b91a20333e3c6271373b Mon Sep 17 00:00:00 2001 From: Puneith Kaul Date: Tue, 31 May 2016 09:49:03 -0700 Subject: [PATCH 19/20] modifid order of import --- .../cloud/speech/grpc/demos/AudioRequestFactoryTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java index 232ff9d5a0d..faa722c57a8 100644 --- a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java +++ b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java @@ -16,9 +16,10 @@ package com.google.cloud.speech.grpc.demos; -import com.google.cloud.speech.v1.AudioRequest; import static org.junit.Assert.assertEquals; +import com.google.cloud.speech.v1.AudioRequest; + import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; From babbf118dfaaf957ac9833c2ad399843151571c7 Mon Sep 17 00:00:00 2001 From: puneith Date: Tue, 31 May 2016 20:34:17 -0700 Subject: [PATCH 20/20] Update AudioRequestFactoryTest.java --- .../google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java index faa722c57a8..8e5017d53f0 100644 --- a/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java +++ b/speech/grpc/src/test/java/com/google/cloud/speech/grpc/demos/AudioRequestFactoryTest.java @@ -54,7 +54,7 @@ public void verifyBytesInSizeFromGoogleStorageFile() throws IOException { int numBytes = audio.getContent().toByteArray().length; - //assert the number of bytes in the audio as 57958 + //assert the number of bytes in the audio as 0 assertEquals(0, numBytes); //assert the uri