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

Commit

Permalink
Add samples to .cloud-repo-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebecca Taylor committed Mar 23, 2018
1 parent d33b076 commit d3ac34d
Show file tree
Hide file tree
Showing 3 changed files with 12,994 additions and 2 deletions.
18 changes: 17 additions & 1 deletion .cloud-repo-tools.json
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",
"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"
}
]
}
51 changes: 50 additions & 1 deletion README.md
@@ -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,55 @@ 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)
.then(results => {
// The binary audio content returned from the API
const audioContent = results[0].audioContent;

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

## 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

0 comments on commit d3ac34d

Please sign in to comment.