-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from GoogleCloudPlatform/speech
Cloud Speech API samples
- Loading branch information
Showing
33 changed files
with
3,036 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=<audio file path> --sampling=<sample rate> | ||
``` | ||
|
||
Try a streaming rate of 16000 and the included sample audio file, as follows: | ||
|
||
```sh | ||
$ bin/speech-sample-nonstreaming.sh --host=speech.googleapis.com --port=443 \ | ||
--file=resources/audio.raw --sampling=16000 | ||
``` | ||
|
||
### Run the streaming client | ||
|
||
You can run the streaming client as follows: | ||
|
||
```sh | ||
$ bin/speech-sample-streaming.sh --host=speech.googleapis.com --port=443 \ | ||
--file=resources/audio.raw --sampling=16000 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
# 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. | ||
|
||
SRC_DIR=$(cd "$(dirname "$0")/.."; pwd) | ||
java -cp ${SRC_DIR}/target/grpc-sample-1.0-jar-with-dependencies.jar \ | ||
com.google.cloud.speech.grpc.demos.NonStreamingRecognizeClient "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
# 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. | ||
|
||
SRC_DIR=$(cd "$(dirname "$0")/.."; pwd) | ||
java -cp ${SRC_DIR}/target/grpc-sample-1.0-jar-with-dependencies.jar \ | ||
com.google.cloud.speech.grpc.demos.RecognizeClient "$@" |
Oops, something went wrong.