📢 Google TTS API
Google TTS (Text-To-Speech) for Node.js without any vulnerabilities. For free without any API keys!
📥 Installation
$ npm install --save google-tts-api
$ npm install -D typescript @types/node
🤔 Usage
Method | Options (all optional) | Return Type | Handle Long Text |
---|
getAudioUrl | lang , slow , host | string | |
getAudioBase64 | lang , slow , host , timeout | Promise<string> | |
getAllAudioUrls | lang , slow , host , splitPunct | { shortText: string; url: string; }[] | ✅ |
getAllAudioBase64 | lang , slow , host , timeout , splitPunct | Promise<{ shortText: string; base64: string; }[]> | ✅ |
Options (all optional)
Option | Type | Default | Description |
---|
lang | string | en | See all available 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. ",、。") |
💻 Examples
1. getAudioUrl(text, [option])
import * as googleTTS from '@sefinek/google-tts-api';
const googleTTS = require('@sefinek/google-tts-api');
const url = googleTTS.getAudioUrl('Hello world!', {
lang: 'en',
slow: false,
host: 'https://translate.google.com',
});
console.log(url);
2. getAudioBase64(text, [option])
import * as googleTTS from '@sefinek/google-tts-api';
const googleTTS = require('@sefinek/google-tts-api');
googleTTS
.getAudioBase64('Hello world!', {
lang: 'en',
slow: false,
host: 'https://translate.google.com',
timeout: 10000,
})
.then(console.log)
.catch(console.error);
3. getAllAudioUrls(text, [option])
(For text longer than 200 characters)
import * as googleTTS from '@sefinek/google-tts-api';
const googleTTS = require('@sefinek/google-tts-api');
const results = googleTTS.getAllAudioUrls('LONG_TEXT_...', {
lang: 'en',
slow: false,
host: 'https://translate.google.com',
splitPunct: ',.?',
});
console.log(results);
4. getAllAudioBase64(text, [option])
(For text longer than 200 characters)
import * as googleTTS from '@sefinek/google-tts-api';
const googleTTS = require('@sefinek/google-tts-api');
googleTTS
.getAllAudioBase64('LONG_TEXT_...', {
lang: 'en',
slow: false,
host: 'https://translate.google.com',
timeout: 10000,
splitPunct: ',.?',
})
.then(console.log)
.catch(console.error);
📑 License
MIT