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

Commit

Permalink
Merge pull request #4 from googleapis/samples
Browse files Browse the repository at this point in the history
Text-to-Speech Code Samples for Listing Voices and Synthesizing Speech
  • Loading branch information
beccasaurus committed Apr 27, 2018
2 parents 4b01b2a + cb32701 commit 3a3fc71
Show file tree
Hide file tree
Showing 24 changed files with 31,092 additions and 26 deletions.
63 changes: 61 additions & 2 deletions .circleci/config.yml
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 @@ -121,6 +129,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 @@ -144,6 +161,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 @@ -155,4 +214,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.
26 changes: 18 additions & 8 deletions .cloud-repo-tools.json
@@ -1,13 +1,23 @@
{
"_product": "text-to-speech",
"id": "text-to-speech",
"name": "Google Cloud Text-To-Speech",
"short_name": "Text-To-Speech",
"docs_url": "https://cloud.google.com/texttospeech",
"description": "Cloud Text-to-Speech API",
"api_id": "texttospeech",
"product": "tts",
"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"
}
]
}
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
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
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
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
Expand Up @@ -4,3 +4,4 @@
# name <email>
#
Alexander Fenster <fenster@google.com>
Rebecca Taylor <rebeccataylor@google.com>
74 changes: 63 additions & 11 deletions README.md
@@ -1,20 +1,22 @@
[//]: # "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)
# [Google Cloud Text-to-Speech API: Node.js Client](https://github.com/googleapis/nodejs-text-to-speech)

[![release level](https://img.shields.io/badge/release%20level-alpha-orange.svg?style&#x3D;flat)](https://cloud.google.com/terms/launch-stages)
[![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)
[![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)
[![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)

> Node.js idiomatic client for [Text-To-Speech][product-docs].
> Node.js idiomatic client for [Cloud Text-to-Speech API][product-docs].
Cloud Text-to-Speech API
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.


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

Read more about the client libraries for Cloud APIs, including the older
Google APIs Client Libraries, in [Client Libraries Explained][explained].
Expand All @@ -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 All @@ -43,7 +46,7 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].

[Enable billing][billing]

1. Enable the Google Cloud Text-To-Speech API.
1. Enable the Google Cloud Text-to-Speech API.

[Enable the API][enable_api]

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

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

### 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');

The [Text-To-Speech Node.js Client API Reference][client-docs] documentation
// 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 [Cloud Text-to-Speech API Node.js Client API Reference][client-docs] documentation
also contains samples.

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

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

0 comments on commit 3a3fc71

Please sign in to comment.