Skip to content

Commit 0ebb546

Browse files
author
jerjou
committed
Organize speech samples into grpc vs REST
1 parent 96996a7 commit 0ebb546

20 files changed

+255
-210
lines changed

speech/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Google Cloud Speech API Samples
2+
3+
These samples show how to use the [Google Cloud Speech API][speech-api]
4+
to transcribe audio files, as well as live audio from your computer's
5+
microphone.
6+
7+
* [`api-client/`](api-client) contains samples that use the [Google API Client
8+
Library for Python][rest-client] to make REST calls to the API.
9+
* [`grpc/`](grpc) contains samples that use the more-efficient (though sometimes
10+
more complex) [GRPC][grpc] API. The GRPC API also allows streaming requests.
11+
12+
[speech-api]: http://cloud.google.com/speech
13+
[rest-client]: https://developers.google.com/api-client-library/python/
14+
[grpc]: http://grpc.io

speech/api-client/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Google Cloud Speech REST API Samples
2+
3+
These samples show how to use the [Google Cloud Speech API](http://cloud.google.com/speech)
4+
to transcribe audio files, using the REST-based [Google API Client Library for
5+
Python](https://developers.google.com/api-client-library/python/).
6+
7+
For samples that use the more-efficient [GRPC](http://grpc.io)-based client
8+
library (including a streaming sample that transcribes audio streamed from your
9+
microphone), see [../grpc/](../grpc/).
10+
11+
## Prerequisites
12+
13+
### Enable the Speech API
14+
15+
If you have not already done so, [enable the Google Cloud Speech
16+
API][console-speech] for your project.
17+
18+
[console-speech]: https://console.cloud.google.com/apis/api/speech.googleapis.com/overview?project=_
19+
20+
### Authentication
21+
22+
These samples use service accounts for authentication.
23+
24+
* Visit the [Cloud Console][cloud-console], and navigate to:
25+
26+
`API Manager > Credentials > Create credentials > Service account key > New
27+
service account`.
28+
* Create a new service account, and download the json credentials file.
29+
* Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to point to your
30+
downloaded service account credentials:
31+
32+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/credentials-key.json
33+
34+
If you do not do this, the REST api will return a 403.
35+
36+
See the [Cloud Platform Auth Guide][auth-guide] for more information.
37+
38+
[cloud-console]: https://console.cloud.google.com
39+
[auth-guide]: https://cloud.google.com/docs/authentication#developer_workflow
40+
41+
### Setup
42+
43+
* Clone this repo
44+
45+
```sh
46+
git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
47+
cd python-docs-samples/speech/api-client
48+
```
49+
50+
* Create a [virtualenv][virtualenv]. This isolates the python dependencies
51+
you're about to install, to minimize conflicts with any existing libraries you
52+
might already have.
53+
54+
```sh
55+
virtualenv env
56+
source env/bin/activate
57+
```
58+
59+
* Install the dependencies
60+
61+
```sh
62+
pip install -r requirements.txt
63+
```
64+
65+
[pip]: https://pip.pypa.io/en/stable/installing/
66+
[virtualenv]: https://virtualenv.pypa.io/en/stable/installation/
67+
68+
## Run the sample
69+
70+
Each of the samples takes the audio file to transcribe as the first argument.
71+
For example:
72+
73+
```sh
74+
python transcribe.py resources/audio.raw
75+
```
76+
77+
You should see a response with the transcription result.
78+
79+
### Deactivate virtualenv
80+
81+
When you're done running the sample, you can exit your virtualenv:
82+
83+
```
84+
deactivate
85+
```
File renamed without changes.

speech/api/speech_async_rest_test.py renamed to speech/api-client/transcribe_async_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import re
1515

16-
from speech_async_rest import main
16+
from transcribe_async import main
1717

1818

1919
def test_main(resource, capsys):

speech/api/speech_rest_test.py renamed to speech/api-client/transcribe_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import re
1515

16-
from speech_rest import main
16+
from transcribe import main
1717

1818

1919
def test_main(resource, capsys):

speech/api/README.md

Lines changed: 0 additions & 133 deletions
This file was deleted.

speech/api/resources/audio.flac

-32.7 KB
Binary file not shown.

speech/api/speech_async_grpc_test.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

speech/api/speech_grpc_test.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)