From ff25b07911525bab1631ad1b4b38eb646fd1d08e Mon Sep 17 00:00:00 2001 From: Amy Unruh Date: Sun, 20 Mar 2016 12:28:11 -0700 Subject: [PATCH 1/3] initial checkin of java grpc speech API examples. Change-Id: Ifc48ab25bfea7ff5ce9ae11caf5c6c483febe705 --- speech/README.md | 8 + speech/grpc/README.md | 100 +++++++ speech/grpc/bin/speech-sample-nonstreaming.sh | 18 ++ speech/grpc/bin/speech-sample-streaming.sh | 18 ++ speech/grpc/pom.xml | 243 +++++++++++++++++ speech/grpc/resources/audio.raw | Bin 0 -> 57958 bytes .../demos/NonStreamingRecognizeClient.java | 209 +++++++++++++++ .../speech/grpc/demos/RecognizeClient.java | 243 +++++++++++++++++ speech/grpc/src/main/proto/.gitignore | 4 + .../main/proto/google/api/annotations.proto | 29 +++ .../grpc/src/main/proto/google/api/http.proto | 245 ++++++++++++++++++ .../src/main/proto/google/api/label.proto | 46 ++++ .../proto/google/api/monitored_resource.proto | 64 +++++ .../src/main/proto/google/logging/README.md | 2 + .../google/logging/type/http_request.proto | 69 +++++ .../google/logging/type/log_severity.proto | 62 +++++ .../proto/google/logging/v2/log_entry.proto | 114 ++++++++ .../proto/google/logging/v2/logging.proto | 167 ++++++++++++ .../google/logging/v2/logging_config.proto | 171 ++++++++++++ .../google/logging/v2/logging_metrics.proto | 146 +++++++++++ .../grpc/src/main/proto/google/rpc/README.md | 5 + .../grpc/src/main/proto/google/rpc/code.proto | 190 ++++++++++++++ .../main/proto/google/rpc/error_details.proto | 157 +++++++++++ .../src/main/proto/google/rpc/status.proto | 90 +++++++ .../proto/google/speech/v1/cloud-speech.proto | 238 +++++++++++++++++ .../grpc/src/main/proto/google/type/README.md | 10 + .../src/main/proto/google/type/color.proto | 163 ++++++++++++ .../src/main/proto/google/type/date.proto | 43 +++ .../main/proto/google/type/dayofweek.proto | 50 ++++ .../src/main/proto/google/type/latlng.proto | 36 +++ .../src/main/proto/google/type/money.proto | 40 +++ .../main/proto/google/type/timeofday.proto | 42 +++ 32 files changed, 3022 insertions(+) create mode 100644 speech/README.md create mode 100644 speech/grpc/README.md create mode 100755 speech/grpc/bin/speech-sample-nonstreaming.sh create mode 100755 speech/grpc/bin/speech-sample-streaming.sh create mode 100644 speech/grpc/pom.xml create mode 100644 speech/grpc/resources/audio.raw create mode 100644 speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/NonStreamingRecognizeClient.java create mode 100644 speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/RecognizeClient.java create mode 100644 speech/grpc/src/main/proto/.gitignore create mode 100644 speech/grpc/src/main/proto/google/api/annotations.proto create mode 100644 speech/grpc/src/main/proto/google/api/http.proto create mode 100644 speech/grpc/src/main/proto/google/api/label.proto create mode 100644 speech/grpc/src/main/proto/google/api/monitored_resource.proto create mode 100644 speech/grpc/src/main/proto/google/logging/README.md create mode 100644 speech/grpc/src/main/proto/google/logging/type/http_request.proto create mode 100644 speech/grpc/src/main/proto/google/logging/type/log_severity.proto create mode 100644 speech/grpc/src/main/proto/google/logging/v2/log_entry.proto create mode 100644 speech/grpc/src/main/proto/google/logging/v2/logging.proto create mode 100644 speech/grpc/src/main/proto/google/logging/v2/logging_config.proto create mode 100644 speech/grpc/src/main/proto/google/logging/v2/logging_metrics.proto create mode 100644 speech/grpc/src/main/proto/google/rpc/README.md create mode 100644 speech/grpc/src/main/proto/google/rpc/code.proto create mode 100644 speech/grpc/src/main/proto/google/rpc/error_details.proto create mode 100644 speech/grpc/src/main/proto/google/rpc/status.proto create mode 100644 speech/grpc/src/main/proto/google/speech/v1/cloud-speech.proto create mode 100644 speech/grpc/src/main/proto/google/type/README.md create mode 100644 speech/grpc/src/main/proto/google/type/color.proto create mode 100644 speech/grpc/src/main/proto/google/type/date.proto create mode 100644 speech/grpc/src/main/proto/google/type/dayofweek.proto create mode 100644 speech/grpc/src/main/proto/google/type/latlng.proto create mode 100644 speech/grpc/src/main/proto/google/type/money.proto create mode 100644 speech/grpc/src/main/proto/google/type/timeofday.proto diff --git a/speech/README.md b/speech/README.md new file mode 100644 index 00000000000..b18c66d1909 --- /dev/null +++ b/speech/README.md @@ -0,0 +1,8 @@ +# Cloud Pub/Sub samples for Java + +This directory contains several samples for the [Cloud Speech API](https://cloud.google.com/speech/) +with Java. + +- [grpc](grpc) + + A sample for accessing Cloud Speech streaming and non streaming apis with [gRPC](http://www.grpc.io/). diff --git a/speech/grpc/README.md b/speech/grpc/README.md new file mode 100644 index 00000000000..68c66975fa4 --- /dev/null +++ b/speech/grpc/README.md @@ -0,0 +1,100 @@ +# Cloud Speech API gRPC samples for Java + +This is a sample repo for accessing the [Google Cloud Speech API](http://cloud.google.com/speech) with +[gRPC](http://www.grpc.io/) client library. + + +## Prerequisites + +### Enable the Speech API + +If you have not already done so, [enable the Google Cloud Speech API for your project](https://console.developers.google.com/apis/api/speech.googleapis.com/overview). +You must be whitelisted to do this. + + +### Download and install Java and Maven + +Install [Java7 or +higher](http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html). + +This sample uses the [Apache Maven][maven] build system. Before getting started, be +sure to [download][maven-download] and [install][maven-install] it. When you use +Maven as described here, it will automatically download the needed client +libraries. + +[maven]: https://maven.apache.org +[maven-download]: https://maven.apache.org/download.cgi +[maven-install]: https://maven.apache.org/install.html + + +### Set Up to Authenticate With Your Project's Credentials + +The example uses a service account for OAuth2 authentication. +So next, set up to authenticate with the Speech API using your project's +service account credentials. + +Visit the [Cloud Console](https://console.developers.google.com), and navigate to: +`API Manager > Credentials > Create credentials > +Service account key > New service account`. +Create a new service account, and download the json credentials file. + +Then, set +the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to point to your +downloaded service account credentials before running this example: + + export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/credentials-key.json + +If you do not do this, you will see an error that looks something like this when +you run the example scripts: +`WARNING: RPC failed: Status{code=PERMISSION_DENIED, description=Request had insufficient authentication scopes., cause=null}`. +See the +[Cloud Platform Auth Guide](https://cloud.google.com/docs/authentication#developer_workflow) +for more information. + +## Build the application + +Then, build the program: + +```sh +$ mvn package +``` + +or + +```sh +$ mvn compile +$ mvn assembly:single +``` + +## Run the clients + +These programs return the transcription of the audio file you provided. Please +note that the audio file must be in RAW format. You can use `sox` +(available, e.g. via [http://sox.sourceforge.net/](http://sox.sourceforge.net/) +or [homebrew](http://brew.sh/)) to convert audio files to raw format. + +### Run the non-streaming client + +You can run the batch client like this: + +```sh +$ bin/speech-sample-nonstreaming.sh --host=speech.googleapis.com --port=443 \ +--file=