google translate tts
1.0.0
このパッケージは、Google翻訳を使用してノードJSでオーディオクリップを作成するためのものです。
このライブラリは、2020年11月にGoogleによって導入されたTranslate APIの新しい変更と連携するように更新されました。
以前の翻訳APIで働いたGoogle-TTS-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 ( ) ;