google tts
1.0.0
Google TTS (Text-to-Speech) für node.js
$ npm install --save google-tts-api
$ npm install -D typescript @types/node # Only for TypeScript Bitte beachten Sie ChangeLog.
| Verfahren | Optionen (alle optional) | Rückgabetyp | Long Text handhaben |
|---|---|---|---|
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; }[]> | ✅ |
| Option | Typ | Standard | Beschreibung |
|---|---|---|---|
lang | string | en | Sehen Sie alle avaierbaren Sprachcode unter https://cloud.google.com/speech/docs/Languages an |
slow | boolean | FALSCH | Verwenden Sie die langsame Audiogeschwindigkeit, wenn Sie slow auf true eingestellt sind |
host | string | https://translate.google.com | Sie können den host ändern, wenn der Standardhost nicht in Ihrer Region funktionieren könnte (z. B. https://translate.google.com.cn). |
timeout | number | 10000 (MS) | (Nur für getAudioBase64 und getAllAudioBase64 ) Stellen Sie die Zeitüberschreitung für die HTTP -Anfrage fest. |
splitPunct | string | (Nur für getAllAudioUrls und getAllAudioBase64 ) Legen Sie die Interpunktion fest, um den langen Text in einen kurzen Text zu teilen. (zB "、。 、。 、。") |
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?...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 ) ;getAllAudioUrls(text, [option]) (für Text länger als 200 Zeichen) 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: '...' },
// ...
// ];getAllAudioBase64(text, [option]) (für Text länger als 200 Zeichen) 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 ) ;Weitere Beispiele
MIT