gta

google-tts-api

Google TTS (Text-To-Speech) for node.js

Showing:

Popularity

Downloads/wk

5.8K

GitHub Stars

195

Maintenance

Last Commit

7mos ago

Contributors

5

Package

Dependencies

1

Size (min+gzip)

7.0KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Readme

google-tts

Google TTS (Text-To-Speech) for node.js

Installation

$ npm install --save google-tts-api
$ npm install -D typescript @types/node # Only for TypeScript

Change Log

Please see CHANGELOG.

Usage

MethodOptions (all optional)Return TypeHandle Long Text
getAudioUrllang, slow, hoststring
getAudioBase64lang, slow, host, timeoutPromise<string>
getAllAudioUrlslang, slow, host, splitPunct{ shortText: string; url: string; }[]
getAllAudioBase64lang, slow, host, timeout, splitPunctPromise<{ shortText: string; base64: string; }[]>

Options (all optional)

OptionTypeDefaultDescription
langstringenSee all avaiable language code at https://cloud.google.com/speech/docs/languages
slowbooleanfalseUse the slow audio speed if set slow to true
hoststringhttps://translate.google.comYou can change the host if the default host could not work in your region (e.g. https://translate.google.com.cn).
timeoutnumber10000 (ms)(Only for getAudioBase64 and getAllAudioBase64) Set timeout for the HTTP request.
splitPunctstring(Only for getAllAudioUrls and getAllAudioBase64) Set the punctuation to split the long text to short text. (e.g. ",、。")

Examples

1. getAudioUrl(text, [option])

import * as googleTTS from 'google-tts-api'; // ES6 or TypeScript
const googleTTS = require('google-tts-api'); // CommonJS

// get audio URL
const url = googleTTS.getAudioUrl('Hello World', {
  lang: 'en',
  slow: false,
  host: 'https://translate.google.com',
});
console.log(url); // https://translate.google.com/translate_tts?...

2. getAudioBase64(text, [option])

import * as googleTTS from 'google-tts-api'; // ES6 or TypeScript
const googleTTS = require('google-tts-api'); // CommonJS

// get base64 text
googleTTS
  .getAudioBase64('Hello World', {
    lang: 'en',
    slow: false,
    host: 'https://translate.google.com',
    timeout: 10000,
  })
  .then(console.log) // base64 text
  .catch(console.error);

3. getAllAudioUrls(text, [option]) (For text longer than 200 characters)

import * as googleTTS from 'google-tts-api'; // ES6 or TypeScript
const googleTTS = require('google-tts-api'); // CommonJS

const results = googleTTS.getAllAudioUrls('LONG_TEXT_...', {
  lang: 'en',
  slow: false,
  host: 'https://translate.google.com',
  splitPunct: ',.?',
});
console.log(results);
// [
//   { shortText: '...', url: '...' },
//   { shortText: '...', url: '...' },
//   ...
// ];

4. getAllAudioBase64(text, [option]) (For text longer than 200 characters)

import * as googleTTS from 'google-tts-api'; // ES6 or TypeScript
const googleTTS = require('google-tts-api'); // CommonJS

googleTTS
  .getAllAudioBase64('LONG_TEXT_...', {
    lang: 'en',
    slow: false,
    host: 'https://translate.google.com',
    timeout: 10000,
    splitPunct: ',.?',
  })
  .then(console.log)
  // [
  //   { shortText: '...', base64: '...' },
  //   { shortText: '...', base64: '...' },
  //   ...
  // ];
  .catch(console.error);

More Examples

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

google-auth-library🔑 Google Auth Library for Node.js
User Rating
4.0/ 5
2
Top Feedback
2Great Documentation
1Easy to Use
GitHub Stars
1K
Weekly Downloads
5M
googleapisGoogle's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
User Rating
4.7/ 5
33
Top Feedback
20Great Documentation
18Easy to Use
15Performant
GitHub Stars
10K
Weekly Downloads
802K
@google-cloud/storageNode.js client for Google Cloud Storage: unified object storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.
User Rating
4.0/ 5
2
Top Feedback
2Performant
2Highly Customizable
1Great Documentation
GitHub Stars
665
Weekly Downloads
2M
@google-cloud/firestoreNode.js client for Google Cloud Firestore: a NoSQL document database built for automatic scaling, high performance, and ease of application development.
User Rating
4.7/ 5
3
Top Feedback
2Great Documentation
2Easy to Use
2Slow
GitHub Stars
522
Weekly Downloads
903K
gl
google-libphonenumberThe up-to-date and reliable Google's libphonenumber package for node.js.
User Rating
4.5/ 5
4
Top Feedback
2Great Documentation
2Easy to Use
2Performant
GitHub Stars
1K
Weekly Downloads
818K
See 18 Alternatives

Tutorials

No tutorials found
Add a tutorial