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

Text-to-Speech Code Samples for Listing Voices and Synthesizing Speech #4

Merged
merged 32 commits into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
880cb25
Sample: List available voices [tts_list_voices]
Mar 22, 2018
fbe2481
Samples: Synthesize Speech (text, ssml, string, local file)
Mar 23, 2018
34dce9b
Merge branch 'master' into samples
alexander-fenster Mar 23, 2018
562a440
Samples: extract speech synthesis samples
Mar 23, 2018
5131b3a
s/var/const/g
Mar 23, 2018
4b01e93
Samples: add quickstart
Mar 23, 2018
d33b076
Samples: change printed output after writing mp3 files
Mar 23, 2018
d3ac34d
Add samples to .cloud-repo-tools
Mar 23, 2018
e9615a1
Merge branch 'samples' of github.com:googleapis/nodejs-text-to-speech…
Mar 23, 2018
6eb1ea6
Samples: update with prettier
Mar 23, 2018
0db5e36
$ npm run generate-scaffolding
Mar 23, 2018
964afec
Samples: fix lint error for unused closure arg var
Mar 23, 2018
d43ad19
Samples: use simple SSML examples, eg. <speak>Hello there.</speak>
Mar 23, 2018
b2ab081
Update links and whatnot
Mar 24, 2018
f47d62e
making lint and samples work in circle
alexander-fenster Mar 24, 2018
6edf91d
Regen README
Mar 24, 2018
11fa592
samples package.json
alexander-fenster Mar 24, 2018
c8c52e2
Merge branch 'samples' of github.com:googleapis/nodejs-text-to-speech…
alexander-fenster Mar 24, 2018
e6fe3f6
Update synthesize.js sample CLI help to show existing TXT and SSML re…
Mar 24, 2018
9e5daf1
Merge branch 'samples' of github.com:googleapis/nodejs-text-to-speech…
Mar 24, 2018
d18510c
s/SSML Gender/SSML Voice Gender/g
Mar 24, 2018
e235bf3
Samples: update writing bytes to mp3 files to be async
Mar 24, 2018
ed07e6b
Update quickstart to write mp3 file asynchronously
Mar 24, 2018
fced808
Samples: Use async I/O when writing MP3 files
Mar 24, 2018
fea561e
Samples - updated with prettier
Mar 24, 2018
811f1ca
Samples: update Quickstart to use async file I/O when writing MP3 file
Mar 24, 2018
01df278
Merge branch 'master' into samples
alexander-fenster Mar 26, 2018
469b101
Upgrade repo-tools to 2.2.6 and run scaffolding
Mar 28, 2018
3cc9711
Merge branch 'samples' of github.com:googleapis/nodejs-text-to-speech…
Mar 28, 2018
754f4ec
Merge branch 'master' into samples
Mar 28, 2018
e383927
Fix typo in README
Apr 27, 2018
cb32701
make lint pass
alexander-fenster Apr 27, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ workflows:
filters:
tags:
only: /.*/
- publish_npm:
- sample_tests:
requires:
- lint
- docs
filters:
branches:
only: master
tags:
only: '/^v[\d.]+$/'
- publish_npm:
requires:
- sample_tests
filters:
branches:
ignore: /.*/
Expand Down Expand Up @@ -112,6 +120,15 @@ jobs:
npm link
environment:
NPM_CONFIG_PREFIX: /home/node/.npm-global
- run:
name: Link the module being tested to the samples.
command: |
cd samples/
npm link @google-cloud/text-to-speech
npm install
cd ..
environment:
NPM_CONFIG_PREFIX: /home/node/.npm-global
- run:
name: Run linting.
command: npm run lint
Expand All @@ -130,6 +147,48 @@ jobs:
- run:
name: Build documentation.
command: npm run docs
sample_tests:
docker:
- image: 'node:8'
user: node
steps:
- checkout
- run: *remove_package_lock
- run:
name: Decrypt credentials.
command: |
openssl aes-256-cbc -d -in .circleci/key.json.enc \
-out .circleci/key.json \
-k "${SYSTEM_TESTS_ENCRYPTION_KEY}"
- run:
name: Install and link the module.
command: |
mkdir -p /home/node/.npm-global
npm install
npm link
environment:
NPM_CONFIG_PREFIX: /home/node/.npm-global
- run:
name: Link the module being tested to the samples.
command: |
cd samples/
npm link @google-cloud/text-to-speech
npm install
cd ..
environment:
NPM_CONFIG_PREFIX: /home/node/.npm-global
- run:
name: Run sample tests.
command: npm run samples-test
environment:
GCLOUD_PROJECT: long-door-651
GOOGLE_APPLICATION_CREDENTIALS: /home/node/text-to-speech-samples/.circleci/key.json
NPM_CONFIG_PREFIX: /home/node/.npm-global
- run:
name: Remove unencrypted key.
command: rm .circleci/key.json
when: always
working_directory: /home/node/text-to-speech-samples
publish_npm:
docker:
- image: 'node:8'
Expand All @@ -141,4 +200,4 @@ jobs:
command: 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'
- run:
name: Publish the module to npm.
command: npm publish --access=public
command: npm publish
Binary file added .circleci/key.json.enc
Binary file not shown.
18 changes: 17 additions & 1 deletion .cloud-repo-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,21 @@
"requiresKeyFile": true,
"requiresProjectId": true,
"client_reference_url": "https://cloud.google.com/nodejs/docs/reference/text-to-speech/latest/",
"release_quality": "alpha"
"release_quality": "alpha",

This comment was marked as spam.

This comment was marked as spam.

"samples": [
{
"id": "synthesize_speech",
"name": "Synthesize Speech",
"file": "synthesize.js",
"docs_link": "https://cloud.google.com/text-to-speech/docs",
"usage": "node synthesize.js --help"
},
{
"id": "list_voices",
"name": "List supported voices",
"file": "listVoices.js",
"docs_link": "https://cloud.google.com/text-to-speech/docs",
"usage": "node listVoices.js --help"
}
]
}
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ possible:
- OS:
- Node.js version:
- npm version:
- `text-to-speech` version:
- `@google-cloud/text-to-speech` version:

#### Steps to reproduce

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
.nyc_output
docs/
out/
build/
system-test/secrets.js
system-test/*key.json
*.lock
.DS_Store
google-cloud-logging-winston-*.tgz
google-cloud-logging-bunyan-*.tgz
2 changes: 1 addition & 1 deletion .jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
copyright: 'Copyright 2017 Google, Inc.',
includeDate: false,
sourceFiles: false,
systemName: 'text-to-speech',
systemName: '@google-cloud/text-to-speech',
theme: 'lumen'
}
};
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
# name <email>
#
Alexander Fenster <[email protected]>
Rebecca Taylor <[email protected]>
58 changes: 55 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
[//]: # "To regenerate it, use `npm run generate-scaffolding`."
<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"/>

# [Google Cloud Text-To-Speech: Node.js Client](https://github.com/googleapis/nodejs-text-to-speech)
Expand Down Expand Up @@ -27,6 +29,7 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].
* [Before you begin](#before-you-begin)
* [Installing the client library](#installing-the-client-library)
* [Using the client library](#using-the-client-library)
* [Samples](#samples)
* [Versioning](#versioning)
* [Contributing](#contributing)
* [License](#license)
Expand Down Expand Up @@ -57,9 +60,58 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].

### Installing the client library

npm install --save text-to-speech


npm install --save @google-cloud/text-to-speech

### Using the client library

```javascript
const fs = require('fs');

// Imports the Google Cloud client library
const textToSpeech = require('@google-cloud/text-to-speech');

// Creates a client
const client = new textToSpeech.TextToSpeechClient();

// The text to synthesize
const text = 'Hello, world!';

// Construct the request
const request = {
input: {text: text},
// Select the language and SSML Voice Gender (optional)
voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'},
// Select the type of audio encoding
audioConfig: {audioEncoding: 'MP3'},
};

// Performs the Text-to-Speech request
client.synthesizeSpeech(request, (err, response) => {
if (err) {
console.error('ERROR:', err);
return;
}

// Write the binary audio content to a local file
fs.writeFile('output.mp3', response.audioContent, 'binary', err => {
if (err) {
console.error('ERROR:', err);
return;
}
console.log('Audio content written to file: output.mp3');
});
});
```

## Samples

Samples are in the [`samples/`](https://github.com/googleapis/nodejs-text-to-speech/tree/master/samples) directory. The samples' `README.md`
has instructions for running the samples.

| Sample | Source Code | Try it |
| --------------------------- | --------------------------------- | ------ |
| 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) |
| 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) |

The [Text-To-Speech Node.js Client API Reference][client-docs] documentation
also contains samples.
Expand Down
Loading