feat: add Google TTS module
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
import { TTSModule, TTSResponse } from '../tts';
|
||||||
|
|
||||||
|
import * as https from 'https';
|
||||||
|
|
||||||
|
import GOOGLE_TTS_VOICES from './google_voices.json';
|
||||||
|
const GOOGLE_TTS_ENDPOINT = 'translate.google.com';
|
||||||
|
const USER_AGENT =
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3';
|
||||||
|
|
||||||
|
const ttsGoogle: TTSModule = {
|
||||||
|
name: 'Google',
|
||||||
|
getVoices: async (): Promise<string[]> => GOOGLE_TTS_VOICES.voices,
|
||||||
|
|
||||||
|
generate: async (voice: string, text: string): Promise<TTSResponse> => {
|
||||||
|
const query = new URLSearchParams({
|
||||||
|
ie: 'UTF-8',
|
||||||
|
q: text,
|
||||||
|
tl: voice,
|
||||||
|
client: 'tw-ob'
|
||||||
|
});
|
||||||
|
|
||||||
|
const options: https.RequestOptions = {
|
||||||
|
hostname: GOOGLE_TTS_ENDPOINT,
|
||||||
|
path: `/translate_tts?${query.toString()}`,
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'User-Agent': USER_AGENT
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const req = https.get(options, (res) => {
|
||||||
|
const chunks: Buffer[] = [];
|
||||||
|
res.on('data', (chunk) => chunks.push(chunk));
|
||||||
|
res.on('end', () => resolve({ data: Buffer.concat(chunks) }));
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('error', (err) => resolve({ error: err.message }));
|
||||||
|
req.on('timeout', () => {
|
||||||
|
req.destroy();
|
||||||
|
resolve({ error: 'timed out' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ttsGoogle;
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
{
|
||||||
|
"voices": [
|
||||||
|
"af",
|
||||||
|
"ar",
|
||||||
|
"bn",
|
||||||
|
"bs",
|
||||||
|
"ca",
|
||||||
|
"cs",
|
||||||
|
"cy",
|
||||||
|
"da",
|
||||||
|
"de",
|
||||||
|
"el",
|
||||||
|
"en",
|
||||||
|
"en-au",
|
||||||
|
"en-ca",
|
||||||
|
"en-gb",
|
||||||
|
"en-gh",
|
||||||
|
"en-ie",
|
||||||
|
"en-in",
|
||||||
|
"en-ng",
|
||||||
|
"en-nz",
|
||||||
|
"en-ph",
|
||||||
|
"en-tz",
|
||||||
|
"en-uk",
|
||||||
|
"en-us",
|
||||||
|
"en-za",
|
||||||
|
"eo",
|
||||||
|
"es",
|
||||||
|
"es-es",
|
||||||
|
"es-us",
|
||||||
|
"et",
|
||||||
|
"fi",
|
||||||
|
"fr",
|
||||||
|
"fr-ca",
|
||||||
|
"fr-fr",
|
||||||
|
"hi",
|
||||||
|
"hr",
|
||||||
|
"hu",
|
||||||
|
"hy",
|
||||||
|
"id",
|
||||||
|
"is",
|
||||||
|
"it",
|
||||||
|
"ja",
|
||||||
|
"jw",
|
||||||
|
"km",
|
||||||
|
"ko",
|
||||||
|
"la",
|
||||||
|
"lv",
|
||||||
|
"mk",
|
||||||
|
"ml",
|
||||||
|
"mr",
|
||||||
|
"my",
|
||||||
|
"ne",
|
||||||
|
"nl",
|
||||||
|
"no",
|
||||||
|
"pl",
|
||||||
|
"pt",
|
||||||
|
"pt-br",
|
||||||
|
"pt-pt",
|
||||||
|
"ro",
|
||||||
|
"ru",
|
||||||
|
"si",
|
||||||
|
"sk",
|
||||||
|
"sq",
|
||||||
|
"sr",
|
||||||
|
"su",
|
||||||
|
"sv",
|
||||||
|
"sw",
|
||||||
|
"ta",
|
||||||
|
"te",
|
||||||
|
"th",
|
||||||
|
"tl",
|
||||||
|
"tr",
|
||||||
|
"uk",
|
||||||
|
"vi",
|
||||||
|
"zh-cn",
|
||||||
|
"zh-tw"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user