Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 3a3fc71

Browse files
authored
Merge pull request #4 from googleapis/samples
Text-to-Speech Code Samples for Listing Voices and Synthesizing Speech
2 parents 4b01b2a + cb32701 commit 3a3fc71

24 files changed

+31092
-26
lines changed

.circleci/config.yml

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ workflows:
3737
filters:
3838
tags:
3939
only: /.*/
40-
- publish_npm:
40+
- sample_tests:
4141
requires:
4242
- lint
4343
- docs
44+
filters:
45+
branches:
46+
only: master
47+
tags:
48+
only: '/^v[\d.]+$/'
49+
- publish_npm:
50+
requires:
51+
- sample_tests
4452
filters:
4553
branches:
4654
ignore: /.*/
@@ -121,6 +129,15 @@ jobs:
121129
npm link
122130
environment:
123131
NPM_CONFIG_PREFIX: /home/node/.npm-global
132+
- run:
133+
name: Link the module being tested to the samples.
134+
command: |
135+
cd samples/
136+
npm link @google-cloud/text-to-speech
137+
npm install
138+
cd ..
139+
environment:
140+
NPM_CONFIG_PREFIX: /home/node/.npm-global
124141
- run:
125142
name: Run linting.
126143
command: npm run lint
@@ -144,6 +161,48 @@ jobs:
144161
- run:
145162
name: Build documentation.
146163
command: npm run docs
164+
sample_tests:
165+
docker:
166+
- image: 'node:8'
167+
user: node
168+
steps:
169+
- checkout
170+
- run: *remove_package_lock
171+
- run:
172+
name: Decrypt credentials.
173+
command: |
174+
openssl aes-256-cbc -d -in .circleci/key.json.enc \
175+
-out .circleci/key.json \
176+
-k "${SYSTEM_TESTS_ENCRYPTION_KEY}"
177+
- run:
178+
name: Install and link the module.
179+
command: |
180+
mkdir -p /home/node/.npm-global
181+
npm install
182+
npm link
183+
environment:
184+
NPM_CONFIG_PREFIX: /home/node/.npm-global
185+
- run:
186+
name: Link the module being tested to the samples.
187+
command: |
188+
cd samples/
189+
npm link @google-cloud/text-to-speech
190+
npm install
191+
cd ..
192+
environment:
193+
NPM_CONFIG_PREFIX: /home/node/.npm-global
194+
- run:
195+
name: Run sample tests.
196+
command: npm run samples-test
197+
environment:
198+
GCLOUD_PROJECT: long-door-651
199+
GOOGLE_APPLICATION_CREDENTIALS: /home/node/text-to-speech-samples/.circleci/key.json
200+
NPM_CONFIG_PREFIX: /home/node/.npm-global
201+
- run:
202+
name: Remove unencrypted key.
203+
command: rm .circleci/key.json
204+
when: always
205+
working_directory: /home/node/text-to-speech-samples
147206
publish_npm:
148207
docker:
149208
- image: 'node:8'
@@ -155,4 +214,4 @@ jobs:
155214
command: 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'
156215
- run:
157216
name: Publish the module to npm.
158-
command: npm publish --access=public
217+
command: npm publish

.circleci/key.json.enc

2.31 KB
Binary file not shown.

.cloud-repo-tools.json

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
{
2-
"_product": "text-to-speech",
3-
"id": "text-to-speech",
4-
"name": "Google Cloud Text-To-Speech",
5-
"short_name": "Text-To-Speech",
6-
"docs_url": "https://cloud.google.com/texttospeech",
7-
"description": "Cloud Text-to-Speech API",
8-
"api_id": "texttospeech",
2+
"product": "tts",
93
"requiresKeyFile": true,
104
"requiresProjectId": true,
115
"client_reference_url": "https://cloud.google.com/nodejs/docs/reference/text-to-speech/latest/",
12-
"release_quality": "alpha"
6+
"release_quality": "alpha",
7+
"samples": [
8+
{
9+
"id": "synthesize_speech",
10+
"name": "Synthesize Speech",
11+
"file": "synthesize.js",
12+
"docs_link": "https://cloud.google.com/text-to-speech/docs",
13+
"usage": "node synthesize.js --help"
14+
},
15+
{
16+
"id": "list_voices",
17+
"name": "List supported voices",
18+
"file": "listVoices.js",
19+
"docs_link": "https://cloud.google.com/text-to-speech/docs",
20+
"usage": "node listVoices.js --help"
21+
}
22+
]
1323
}

.github/ISSUE_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ possible:
1515
- OS:
1616
- Node.js version:
1717
- npm version:
18-
- `text-to-speech` version:
18+
- `@google-cloud/text-to-speech` version:
1919

2020
#### Steps to reproduce
2121

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
.nyc_output
55
docs/
66
out/
7+
build/
78
system-test/secrets.js
89
system-test/*key.json
910
*.lock
11+
.DS_Store
12+
google-cloud-logging-winston-*.tgz
13+
google-cloud-logging-bunyan-*.tgz

.jsdoc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939
copyright: 'Copyright 2017 Google, Inc.',
4040
includeDate: false,
4141
sourceFiles: false,
42-
systemName: 'text-to-speech',
42+
systemName: '@google-cloud/text-to-speech',
4343
theme: 'lumen'
4444
}
4545
};

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
# name <email>
55
#
66
Alexander Fenster <[email protected]>
7+
Rebecca Taylor <[email protected]>

README.md

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1+
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
2+
[//]: # "To regenerate it, use `npm run generate-scaffolding`."
13
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
24

3-
# [Google Cloud Text-To-Speech: Node.js Client](https://github.com/googleapis/nodejs-text-to-speech)
5+
# [Google Cloud Text-to-Speech API: Node.js Client](https://github.com/googleapis/nodejs-text-to-speech)
46

57
[![release level](https://img.shields.io/badge/release%20level-alpha-orange.svg?style&#x3D;flat)](https://cloud.google.com/terms/launch-stages)
68
[![CircleCI](https://img.shields.io/circleci/project/github/googleapis/nodejs-text-to-speech.svg?style=flat)](https://circleci.com/gh/googleapis/nodejs-text-to-speech)
79
[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/googleapis/nodejs-text-to-speech?branch=master&svg=true)](https://ci.appveyor.com/project/googleapis/nodejs-text-to-speech)
810
[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-text-to-speech/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-text-to-speech)
911

10-
> Node.js idiomatic client for [Text-To-Speech][product-docs].
12+
> Node.js idiomatic client for [Cloud Text-to-Speech API][product-docs].
1113
12-
Cloud Text-to-Speech API
14+
The [Cloud Text-to-Speech API](https://cloud.google.com/text-to-speech/docs) converts text or Speech Synthesis Markup Language (SSML) input into audio data of natural human speech.
1315

1416

15-
* [Text-To-Speech Node.js Client API Reference][client-docs]
17+
* [Cloud Text-to-Speech API Node.js Client API Reference][client-docs]
1618
* [github.com/googleapis/nodejs-text-to-speech](https://github.com/googleapis/nodejs-text-to-speech)
17-
* [Text-To-Speech Documentation][product-docs]
19+
* [Cloud Text-to-Speech API Documentation][product-docs]
1820

1921
Read more about the client libraries for Cloud APIs, including the older
2022
Google APIs Client Libraries, in [Client Libraries Explained][explained].
@@ -27,6 +29,7 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].
2729
* [Before you begin](#before-you-begin)
2830
* [Installing the client library](#installing-the-client-library)
2931
* [Using the client library](#using-the-client-library)
32+
* [Samples](#samples)
3033
* [Versioning](#versioning)
3134
* [Contributing](#contributing)
3235
* [License](#license)
@@ -43,7 +46,7 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].
4346

4447
[Enable billing][billing]
4548

46-
1. Enable the Google Cloud Text-To-Speech API.
49+
1. Enable the Google Cloud Text-to-Speech API.
4750

4851
[Enable the API][enable_api]
4952

@@ -52,16 +55,65 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].
5255

5356
[projects]: https://console.cloud.google.com/project
5457
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
55-
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=texttospeech
58+
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=texttospeech.googleapis.com
5659
[auth]: https://cloud.google.com/docs/authentication/getting-started
5760

5861
### Installing the client library
5962

60-
npm install --save text-to-speech
63+
npm install --save @google-cloud/text-to-speech
6164

65+
### Using the client library
6266

67+
```javascript
68+
const fs = require('fs');
6369

64-
The [Text-To-Speech Node.js Client API Reference][client-docs] documentation
70+
// Imports the Google Cloud client library
71+
const textToSpeech = require('@google-cloud/text-to-speech');
72+
73+
// Creates a client
74+
const client = new textToSpeech.TextToSpeechClient();
75+
76+
// The text to synthesize
77+
const text = 'Hello, world!';
78+
79+
// Construct the request
80+
const request = {
81+
input: {text: text},
82+
// Select the language and SSML Voice Gender (optional)
83+
voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'},
84+
// Select the type of audio encoding
85+
audioConfig: {audioEncoding: 'MP3'},
86+
};
87+
88+
// Performs the Text-to-Speech request
89+
client.synthesizeSpeech(request, (err, response) => {
90+
if (err) {
91+
console.error('ERROR:', err);
92+
return;
93+
}
94+
95+
// Write the binary audio content to a local file
96+
fs.writeFile('output.mp3', response.audioContent, 'binary', err => {
97+
if (err) {
98+
console.error('ERROR:', err);
99+
return;
100+
}
101+
console.log('Audio content written to file: output.mp3');
102+
});
103+
});
104+
```
105+
106+
## Samples
107+
108+
Samples are in the [`samples/`](https://github.com/googleapis/nodejs-text-to-speech/tree/master/samples) directory. The samples' `README.md`
109+
has instructions for running the samples.
110+
111+
| Sample | Source Code | Try it |
112+
| --------------------------- | --------------------------------- | ------ |
113+
| Synthesize Speech | [source code](https://github.com/googleapis/nodejs-text-to-speech/blob/master/samples/synthesize.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-text-to-speech&page=editor&open_in_editor=samples/synthesize.js,samples/README.md) |
114+
| List supported voices | [source code](https://github.com/googleapis/nodejs-text-to-speech/blob/master/samples/listVoices.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-text-to-speech&page=editor&open_in_editor=samples/listVoices.js,samples/README.md) |
115+
116+
The [Cloud Text-to-Speech API Node.js Client API Reference][client-docs] documentation
65117
also contains samples.
66118

67119
## Versioning
@@ -87,5 +139,5 @@ Apache Version 2.0
87139
See [LICENSE](https://github.com/googleapis/nodejs-text-to-speech/blob/master/LICENSE)
88140

89141
[client-docs]: https://cloud.google.com/nodejs/docs/reference/text-to-speech/latest/
90-
[product-docs]: https://cloud.google.com/texttospeech
91-
[shell_img]: //gstatic.com/cloudssh/images/open-btn.png
142+
[product-docs]: https://cloud.google.com/text-to-speech/docs
143+
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png

0 commit comments

Comments
 (0)