google translate tts
1.0.0
Ce package est destiné à utiliser Google Translate pour créer des clips audio dans le nœud JS.
Cette bibliothèque a été mise à jour pour travailler avec les nouvelles modifications de l'API Translate introduites par Google en novembre 2020.
Un successeur spirituel de Google-TTS-API qui a travaillé avec la précédente API Translate.
npm install google-translate-tts
ou
yarn add google-translate-tts
Trouvez une voix à utiliser:
const tts = require ( 'google-translate-tts' ) ;
// lookup by name
const voice = tts . voices . findByName ( 'English (United States)' ) ;
// lookup by code
const voice = tts . voices . findByCode ( 'en-US' ) ;
// an array of all voices
console . log ( tts . voices ) ;
/* Voice example:
* {
* code: 'en-US',
* name: 'English (United States)'
* }
*/Téléchargez un clip audio:
const fs = require ( 'fs' ) ;
const tts = require ( 'google-translate-tts' ) ;
// notice that `tts.synthesize` returns a Promise<Buffer>
const saveFile = async ( ) => {
const buffer = await tts . synthesize ( {
text : 'Hello, world!' ,
voice : 'en-US' ,
slow : false // optional
} ) ;
fs . writeFileSync ( 'hello-world.mp3' , buffer ) ;
} ;
saveFile ( ) ;