Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@google-cloud/text-to-speech

googleapis234.2kApache-2.06.1.0TypeScript support: included

Cloud Text-to-Speech API client for Node.js

google apis client, google api client, google apis, google api, google, google cloud platform, google cloud, cloud, google texttospeech, texttospeech, Cloud Text-to-Speech API

readme

Google Cloud Platform logo

Google Cloud Text-to-Speech: Node.js Client

release level npm version

Cloud Text-to-Speech API client for Node.js

A comprehensive list of changes in each version may be found in the CHANGELOG.

Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.

Table of contents:

Quickstart

Before you begin

  1. Select or create a Cloud Platform project.
  2. Enable billing for your project.
  3. Enable the Google Cloud Text-to-Speech API.
  4. Set up authentication with a service account so you can access the API from your local workstation.

Installing the client library

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

Using the client library

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

// Import other required libraries
const fs = require('fs');
const util = require('util');
// Creates a client
const client = new textToSpeech.TextToSpeechClient();
async function quickStart() {
  // 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
  const [response] = await client.synthesizeSpeech(request);
  // Write the binary audio content to a local file
  const writeFile = util.promisify(fs.writeFile);
  await writeFile('output.mp3', response.audioContent, 'binary');
  console.log('Audio content written to file: output.mp3');
}
quickStart();

Samples

Samples are in the samples/ directory. Each sample's README.md has instructions for running its sample.

Sample Source Code Try it
Text_to_speech.list_voices source code Open in Cloud Shell
Text_to_speech.streaming_synthesize source code Open in Cloud Shell
Text_to_speech.synthesize_speech source code Open in Cloud Shell
Text_to_speech_long_audio_synthesize.synthesize_long_audio source code Open in Cloud Shell
Text_to_speech.list_voices source code Open in Cloud Shell
Text_to_speech.streaming_synthesize source code Open in Cloud Shell
Text_to_speech.synthesize_speech source code Open in Cloud Shell
Text_to_speech_long_audio_synthesize.synthesize_long_audio source code Open in Cloud Shell
Quickstart source code Open in Cloud Shell

The Google Cloud Text-to-Speech Node.js Client API Reference documentation also contains samples.

Supported Node.js Versions

Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js. If you are using an end-of-life version of Node.js, we recommend that you update as soon as possible to an actively supported LTS version.

Google's client libraries support legacy versions of Node.js runtimes on a best-efforts basis with the following warnings:

  • Legacy versions are not tested in continuous integration.
  • Some security patches and features cannot be backported.
  • Dependencies cannot be kept up-to-date.

Client libraries targeting some end-of-life versions of Node.js are available, and can be installed through npm dist-tags. The dist-tags follow the naming convention legacy-(version). For example, npm install @google-cloud/text-to-speech@legacy-8 installs client libraries for versions compatible with Node.js 8.

Versioning

This library follows Semantic Versioning.

This library is considered to be stable. The code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against stable libraries are addressed with the highest priority.

More Information: Google Cloud Platform Launch Stages

Contributing

Contributions welcome! See the Contributing Guide.

Please note that this README.md, the samples/README.md, and a variety of configuration files in this repository (including .nycrc and tsconfig.json) are generated from a central template. To edit one of these files, make an edit to its templates in directory.

License

Apache Version 2.0

See LICENSE

changelog

Changelog

npm history

6.1.0 (2025-05-09)

Features

  • [texttospeech] Support HD voice custom pronunciations (#6229) (f1f9df8)

6.0.1 (2025-03-19)

Bug Fixes

  • [Many APIs] await/catch promises, and update listOperationsAsync return type (#6189) (0eab6d4)

6.0.0 (2025-03-18)

⚠ BREAKING CHANGES

  • upgrade to Node 18 (#6096)

Features

  • Add request/response debug logging to gapics, update templates to gax 5 and node 18 (#1671) (eed00f4)

Bug Fixes

  • Add json files to tsconfig templates (#1692) (ba6be1d) (eed00f4)

Miscellaneous Chores

5.8.1 (2025-02-12)

Bug Fixes

  • [Many APIs] finalize fixing typings for headers in generator (#6018) (9dc5856)

5.8.0 (2025-01-11)

Features

  • [texttospeech] StreamingSynthesize now supports opus (#5926) (d8d7c9a)

5.7.0 (2024-12-18)

Features

  • [texttospeech] StreamingSynthesize now supports opus (#5887) (c335f19)

5.6.0 (2024-10-30)

Features

  • [texttospeech] add multi-speaker markup, which allows generating dialogue between multiple speakers (#5760) (f9dea89)

5.5.0 (2024-10-10)

Features

  • [texttospeech] Add low latency journey option to proto (#5742) (d34249c)

5.4.0 (2024-08-19)

Features

  • [texttospeech] A new method StreamingSynthesize is added to service TextToSpeech (#5620) (a8d513d)

5.3.0 (2024-05-21)

Features

  • [Many APIs] update Nodejs generator to send API versions in headers for GAPICs (#5351) (01f48fc)
  • [Many APIs] update Nodejs generator to send API versions in headers for GAPICs (#5354) (a9784ed)

5.2.0 (2024-03-29)

Features

  • [Many APIs] add several fields to manage state of database encryption update (#5191) (57567db)

5.1.0 (2024-02-09)

Features

  • Trusted Private Cloud support, use the universeDomain parameter (#5028) (852f3eb)

5.0.2 (2024-01-15)

Bug Fixes

  • [texttospeech] correct long audio synthesis HTTP binding (#4916) (0be8b3e)

5.0.1 (2023-09-06)

Bug Fixes

  • [Many APIs] simplify logic for HTTP/1.1 REST fallback option (#4588) (e5ad564)

5.0.0 (2023-08-06)

⚠ BREAKING CHANGES

  • migrate to Node 14 (#4443)

Bug Fixes

Miscellaneous Chores

4.2.3 (2023-06-28)

Bug Fixes

4.2.2 (2023-04-13)

Bug Fixes

4.2.1 (2023-02-15)

Bug Fixes

  • [Many APIs] changing format of the jsdoc links (#3989) (95399f7)

4.2.0 (2023-01-28)

Features

4.1.0 (2022-12-16)

Features

4.0.4 (2022-11-09)

Bug Fixes

4.0.3 (2022-09-14)

Bug Fixes

  • Allow passing gax instance to client constructor (#625) (df7fc10)
  • Do not import the whole google-gax from proto JS (#1553) (#624) (655571f)
  • Preserve default values in x-goog-request-params header (#627) (26a4f84)
  • use google-gax v3.3.0 (655571f)

4.0.2 (2022-08-23)

Bug Fixes

4.0.1 (2022-06-30)

Bug Fixes

4.0.0 (2022-06-10)

⚠ BREAKING CHANGES

  • update library to use Node 12 (#604)

Features

  • Consolidate task details into service API and add orchestration result details (74f7cfb)
  • promote CustomVoiceParams to v1 (#591) (fe647dc)

Build System

3.4.0 (2021-12-09)

Features

3.3.1 (2021-09-10)

Bug Fixes

3.3.0 (2021-08-23)

Features

  • turns on self-signed JWT feature flag (#543) (bd5ecd3)

3.2.7 (2021-08-17)

Bug Fixes

3.2.6 (2021-07-21)

Bug Fixes

  • Updating WORKSPACE files to use the newest version of the Typescript generator. (#534) (dee8dc2)

3.2.5 (2021-07-12)

Bug Fixes

3.2.4 (2021-06-30)

Bug Fixes

3.2.3 (2021-06-23)

Bug Fixes

3.2.2 (2021-06-04)

Bug Fixes

  • GoogleAdsError missing using generator version after 1.3.0 (#515) (f48e238)

3.2.1 (2021-05-12)

Bug Fixes

3.2.0 (2021-04-16)

Features

  • add ALAW support on client library. And improve the ListVoiceRequest message's documentation (#490) (0c5217c)

3.1.3 (2020-11-25)

Bug Fixes

  • browser: check for fetch on window (a0925b3)

3.1.2 (2020-11-06)

Bug Fixes

  • do not modify options object, use defaultScopes (#463) (c3558d8)

3.1.1 (2020-09-12)

Bug Fixes

  • deps: update dependency yargs to v16 (#446) (d069082)

3.1.0 (2020-07-30)

Features

  • support MULAW and MP3_64_KBPS audio encoding and support timepointing via SSML tag (8826c87)

3.0.1 (2020-06-29)

Bug Fixes

3.0.0 (2020-06-04)

⚠ BREAKING CHANGES

  • The library now supports Node.js v10+. The last version to support Node.js v8 is tagged legacy-8 on NPM.

Features

Bug Fixes

  • regen protos and tests, formatting (#401) (6c7d38a)
  • remove eslint, update gax, fix generated protos, run the generator (#385) (f035747)
  • remove unused files in package (#389) (7b1e5e4)
  • synth.py clean up for multiple version (#403) (1b36546)

2.3.0 (2020-03-06)

Features

2.2.0 (2020-02-12)

Features

2.1.3 (2020-02-01)

Bug Fixes

  • enum, bytes, and Long types now accept strings (3839359)

2.1.2 (2020-01-03)

Bug Fixes

  • "client already closed" error fires earlier (41b39bc)

2.1.1 (2019-12-30)

Bug Fixes

2.1.0 (2019-12-11)

Features

  • make service stub public (921f404)

Bug Fixes

  • deps: pin TypeScript below 3.7.0 (4da93ee)

2.0.2 (2019-11-20)

Bug Fixes

2.0.1 (2019-11-18)

Bug Fixes

  • deps: update dependency yargs to v15 (#295) (2c7eea2)

2.0.0 (2019-11-14)

⚠ BREAKING CHANGES

  • move library to typescript code generation (#285)

Starting with this release, the auto-generated library code was changed from JavaScript to TypeScript, so all the TypeScript types are now exported from the .d.ts files.

Please note that if you used @types/google-cloud__text-to-speech package to get TypeScript types for this library, you need to stop using it and remove it from your devDependencies.

If you see any issues caused by this migration to TypeScript, please feel free to submit an issue!

Features

  • move library to typescript code generation (#285) (d3d6208)

Bug Fixes

  • import long into proto ts declaration file (#288) (5bfb2ab)
  • docs: snippets are now replaced in jsdoc comments (#287) (6e77aaf)

1.4.1 (2019-10-22)

Bug Fixes

1.4.0 (2019-10-09)

Bug Fixes

  • use compatible version of google-gax (475c794)

Features

1.3.0 (2019-09-16)

Bug Fixes

  • docs: READMEs updated with new samples (d3e09e0)
  • add proto field behavior options (#265) (1f184a3)

Features

  • code samples for ssml addresses tutorial (#257) (e423f2a)

1.2.0 (2019-09-05)

Features

  • load protos from JSON, grpc-fallback support (c9a203d)

1.1.4 (2019-08-28)

Bug Fixes

  • deps: update dependency yargs to v14 (8392e8b)
  • use correct version for x-goog-api-client header (6e03123)

1.1.3 (2019-08-02)

Bug Fixes

  • allow calls with no request, add JSON proto (cb8a51b)

1.1.2 (2019-06-26)

Bug Fixes

  • docs: link to reference docs section on googleapis.dev (#242) (f05140a)

1.1.1 (2019-06-13)

Bug Fixes

1.1.0 (2019-06-05)

Features

  • support apiEndpoint override in client constructor (#234) (519c36c)

1.0.0 (2019-05-14)

Bug Fixes

  • deps: update dependency google-gax to v1 (#223) (aa8bbed)
  • DEADLINE_EXCEEDED is idempotent (#224) (affbbd1)
  • DEADLINE_EXCEEDED no longer treated as idempotent and retried (9e5baee)
  • deps: update dependency google-gax to ^0.26.0 (#212) (30ea99f)

Build System

BREAKING CHANGES

  • upgrade engines field to >=8.10.0 (#214)

v0.5.1

02-14-2019 17:36 PST

Bug Fixes

  • fix: throw on invalid credentials (#189)

Documentation

  • docs: update sample to show method inside of async function (#188)
  • docs: update links in contrib guide (#191)
  • docs: update contributing path in README (#184)

Internal / Testing Changes

  • build: use linkinator for docs test (#190)
  • fix(deps): update dependency yargs to v13 (#187)
  • build: create docs test npm scripts (#186)
  • build: test using @grpc/grpc-js in CI (#185)
  • chore: move CONTRIBUTING.md to root (#183)

v0.5.0

02-05-2019 13:22 PST

New Features

  • feat: add the effects_profile_id property. (#173)

    Dependencies

  • fix(deps): update dependency google-gax to ^0.25.0 (#178)
  • chore(deps): update dependency eslint-config-prettier to v4 (#176)
  • fix(deps): update dependency google-gax to ^0.24.0 (#175)
  • fix(deps): update dependency google-gax to ^0.23.0 (#170)

    Documentation

  • build: ignore googleapis.com in doc link check (#174)
  • docs: fix dead link to audio profiles (#177)
  • fix(docs): fix require stmt (#166)
  • build: check broken links in generated docs (#165)

    Internal / Testing Changes

  • test: add a smoke test (#172)
  • refactor: modernize the sample tests (#164)
  • chore(build): inject yoshi automation key (#161)
  • chore: update nyc and eslint configs (#160)
  • chore: fix publish.sh permission +x (#158)
  • fix(build): fix Kokoro release script (#157)
  • build: add Kokoro configs for autorelease (#156)
  • chore: always nyc report before calling codecov (#152)

v0.4.0

12-05-2018 16:31 PST

Implementation Changes

  • chore: require node 8 for samples (#61)

Dependencies

  • chore: remove unused deps and cleanup (#125)
  • chore: removed async from dependency list (#140)
  • fix(deps): update dependency google-gax to ^0.22.0 (#132)
  • chore(deps): update dependency @google-cloud/nodejs-repo-tools to v3 (#129)
  • chore(deps): update dependency through2 to v3 (#123)
  • chore(deps): update dependency eslint-plugin-node to v8 (#114)
  • chore(deps): update dependency canvas to v2 (#102)
  • chore(deps): update dependency eslint-plugin-prettier to v3 (#98)
  • fix(deps): update dependency google-gax to ^0.20.0 (#85)
  • chore(deps): update dependency nyc to v13 (#78)
  • fix(deps): update dependency google-gax to ^0.19.0 (#76)
  • Update region tags to standard (#75)
  • chore(deps): update dependency eslint-config-prettier to v3 (#73)
  • chore(deps): lock file maintenance (#68)
  • chore(deps): lock file maintenance (#67)
  • fix(deps): update dependency google-gax to ^0.18.0 (#63)
  • chore(deps): lock file maintenance (#62)
  • chore(deps): lock file maintenance (#59)
  • chore(deps): update dependency eslint-plugin-node to v7 (#57)
  • chore(deps): lock file maintenance (#56)

Documentation

  • fix(docs): bad namespaces causing 404s (#149)
  • docs: update readme badges (#143)
  • docs(samples): updated samples code to use async await (#118)

Internal / Testing Changes

  • chore: nyc ignore build/test by default (#148)
  • chore: clean up usage of prettier and eslint (#147)
  • chore: update license file (#145)
  • fix(build): fix system key decryption (#141)
  • refactor(samples): convert sample tests from ava to mocha (#133)
  • chore: add a synth.metadata
  • chore: drop contributors from multiple places (#126)
  • chore: use latest npm on Windows (#124)
  • chore: update eslintignore
  • chore: update CircleCI config (#121)
  • chore: update issue templates (#113)
  • chore: remove old issue template (#111)
  • build: run tests on node11 (#110)
  • chores(build): do not collect sponge.xml from windows builds (#109)
  • chores(build): run codecov on continuous builds (#108)
  • chore: update new issue template (#107)
  • build: fix codecov uploading on Kokoro (#101)
  • Update kokoro config (#99)
  • build: prevent system/sample-test from leaking credentials
  • Update the kokoro config (#94)
  • test: remove appveyor config (#93)
  • Update the CI config (#92)
  • Fix the linter (#90)
  • Enable prefer-const in the eslint config (#88)
  • Enable no-var in eslint (#87)
  • Switch to let/const (#86)
  • Update CI config (#84)
  • Update CI config (#83)
  • Retry npm install in CI (#81)
  • Add templates to synth.py and run it (#79)
  • chore: do not use npm ci (#72)
  • chore: ignore package-lock.json (#69)
  • chore: update renovate config (#65)
  • chore: remove bonus whitespace
  • Code Samples demonstrating Audio Profiles (#31)
  • remove that whitespace (#64)
  • chore: move mocha options to mocha.opts (#60)
  • test: use strictEqual in tests (#58)

v0.3.0

Implementation Changes

  • Fixed the wrong region tag (#46)

Breaking Change:

  • fix: drop support for node.js 4.x and 9.x (#49)

New Features

  • v1 GA is released (#29) 🎉

Dependencies

  • Update synth.py and update google-gax to 0.17.0 (#45)
  • chore(deps): update dependency eslint to v5 (#42)
  • fix(deps): update dependency yargs to v12 (#44)
  • chore(deps): update dependency ava to ^0.25.0 (#37)
  • fix(deps): update dependency yargs to v11 (#43)
  • chore(deps): update dependency @google-cloud/nodejs-repo-tools to v2.3.0 (#36)

Documentation

  • fix: update linking for samples (#33)

Internal / Testing Changes

  • Configure Renovate (#30)
  • refactor: drop repo-tool as an exec wrapper (#35)