Skip to content

Commit 6e830be

Browse files
committed
Merge pull request GoogleCloudPlatform#138 from GoogleCloudPlatform/speech
Cloud Speech API samples
2 parents 847bcc5 + e747f5e commit 6e830be

33 files changed

+3036
-0
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<module>managed_vms/twilio</module>
7070
<module>monitoring/v2</module>
7171
<module>monitoring/v3</module>
72+
<module>speech/grpc</module>
7273
<module>storage/json-api</module>
7374
<module>storage/storage-transfer</module>
7475
<module>storage/xml-api/cmdline-sample</module>

speech/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Cloud Pub/Sub samples for Java
2+
3+
This directory contains several samples for the [Cloud Speech API](https://cloud.google.com/speech/)
4+
with Java.
5+
6+
- [grpc](grpc)
7+
8+
A sample for accessing Cloud Speech streaming and non streaming apis with [gRPC](http://www.grpc.io/).

speech/grpc/README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Cloud Speech API gRPC samples for Java
2+
3+
This is a sample repo for accessing the [Google Cloud Speech API](http://cloud.google.com/speech) with
4+
[gRPC](http://www.grpc.io/) client library.
5+
6+
7+
## Prerequisites
8+
9+
### Enable the Speech API
10+
11+
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).
12+
You must be whitelisted to do this.
13+
14+
15+
### Download and install Java and Maven
16+
17+
Install [Java7 or
18+
higher](http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html).
19+
20+
This sample uses the [Apache Maven][maven] build system. Before getting started, be
21+
sure to [download][maven-download] and [install][maven-install] it. When you use
22+
Maven as described here, it will automatically download the needed client
23+
libraries.
24+
25+
[maven]: https://maven.apache.org
26+
[maven-download]: https://maven.apache.org/download.cgi
27+
[maven-install]: https://maven.apache.org/install.html
28+
29+
30+
### Set Up to Authenticate With Your Project's Credentials
31+
32+
The example uses a service account for OAuth2 authentication.
33+
So next, set up to authenticate with the Speech API using your project's
34+
service account credentials.
35+
36+
Visit the [Cloud Console](https://console.developers.google.com), and navigate to:
37+
`API Manager > Credentials > Create credentials >
38+
Service account key > New service account`.
39+
Create a new service account, and download the json credentials file.
40+
41+
Then, set
42+
the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to point to your
43+
downloaded service account credentials before running this example:
44+
45+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/credentials-key.json
46+
47+
If you do not do this, you will see an error that looks something like this when
48+
you run the example scripts:
49+
`WARNING: RPC failed: Status{code=PERMISSION_DENIED, description=Request had insufficient authentication scopes., cause=null}`.
50+
See the
51+
[Cloud Platform Auth Guide](https://cloud.google.com/docs/authentication#developer_workflow)
52+
for more information.
53+
54+
## Build the application
55+
56+
Then, build the program:
57+
58+
```sh
59+
$ mvn package
60+
```
61+
62+
or
63+
64+
```sh
65+
$ mvn compile
66+
$ mvn assembly:single
67+
```
68+
69+
## Run the clients
70+
71+
These programs return the transcription of the audio file you provided. Please
72+
note that the audio file must be in RAW format. You can use `sox`
73+
(available, e.g. via [http://sox.sourceforge.net/](http://sox.sourceforge.net/)
74+
or [homebrew](http://brew.sh/)) to convert audio files to raw format.
75+
76+
### Run the non-streaming client
77+
78+
You can run the batch client like this:
79+
80+
```sh
81+
$ bin/speech-sample-nonstreaming.sh --host=speech.googleapis.com --port=443 \
82+
--file=<audio file path> --sampling=<sample rate>
83+
```
84+
85+
Try a streaming rate of 16000 and the included sample audio file, as follows:
86+
87+
```sh
88+
$ bin/speech-sample-nonstreaming.sh --host=speech.googleapis.com --port=443 \
89+
--file=resources/audio.raw --sampling=16000
90+
```
91+
92+
### Run the streaming client
93+
94+
You can run the streaming client as follows:
95+
96+
```sh
97+
$ bin/speech-sample-streaming.sh --host=speech.googleapis.com --port=443 \
98+
--file=resources/audio.raw --sampling=16000
99+
```
100+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
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+
SRC_DIR=$(cd "$(dirname "$0")/.."; pwd)
17+
java -cp ${SRC_DIR}/target/grpc-sample-1.0-jar-with-dependencies.jar \
18+
com.google.cloud.speech.grpc.demos.NonStreamingRecognizeClient "$@"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
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+
SRC_DIR=$(cd "$(dirname "$0")/.."; pwd)
17+
java -cp ${SRC_DIR}/target/grpc-sample-1.0-jar-with-dependencies.jar \
18+
com.google.cloud.speech.grpc.demos.RecognizeClient "$@"

0 commit comments

Comments
 (0)