google translate tts
1.0.0
此软件包用于使用Google Translate在节点JS中创建音频剪辑。
该库已更新,以处理Google在2020年11月引入的Translate API的新更改。
Google-TTS-API的精神继任者,与以前的翻译API合作。
npm install google-translate-tts
或者
yarn add google-translate-tts
找到使用的声音:
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)'
* }
*/下载音频剪辑:
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 ( ) ;