Package Exports
- google-tts-api
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (google-tts-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
google-tts
Google TTS (Text-To-Speech) for node.js
Installation
$ npm install --save google-tts-api
Change Log
Please see CHANGELOG.
Usage
1. getAudioUrl(text, [option])
- Available options:
lang
,slow
,host
- Example:
const googleTTS = require('google-tts-api'); // get audio URL const url = googleTTS.getAudioUrl('Hello World', { lang: 'en-US', slow: false, host: 'https://translate.google.com', }); console.log(url); // https://translate.google.com/translate_tts?...
2. getAudioBase64(text, [option])
- This is a promise function
- Available options:
lang
,slow
,host
,timeout
- Example:
const googleTTS = require('google-tts-api'); // get base64 text googleTTS .getAudioBase64('Hello World', { lang: 'en-US', 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)
- Available options:
lang
,slow
,host
,splitPunct
- Example:
const googleTTS = require('google-tts-api'); const results = googleTTS.getAllAudioUrls('LONG_TEXT_...', { lang: 'en-US', 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)
- This is a promise function
- Available options:
lang
,slow
,host
,timeout
,splitPunct
- Example:
const googleTTS = require('google-tts-api'); googleTTS .getAllAudioBase64('LONG_TEXT_...', { lang: 'en-US', slow: false, host: 'https://translate.google.com', timeout: 10000, splitPunct: ',.?', }) .then(console.log) // [ // { shortText: '...', base64: '...' }, // { shortText: '...', base64: '...' }, // ... // ]; .catch(console.error);
Options (All options are optional)
Option | Type | Default | Description |
---|---|---|---|
lang |
string |
en-US | See all avaiable language code at https://cloud.google.com/speech/docs/languages |
slow |
boolean |
false | Use the slow audio speed if set slow to true |
host |
string |
https://translate.google.com | You can change the host if the default host could not work in your region (e.g. https://translate.google.com.cn). |
timeout |
number |
10000 (ms) | (Only for getAudioBase64 and getAllAudioBase64 ) Set timeout for the HTTP request. |
splitPunct |
string |
(Only for getAllAudioUrls and getAllAudioBase64 ) Set the punctuation to split the long text to short text. (e.g. ",、。") |
License
MIT