UNPKG

@sefinek/google-tts-api

Version:

Fast Google TTS (Text-To-Speech) for Node.js. For free without any API keys!

19 lines (15 loc) 565 B
const fs = require('fs'); const googleTTS = require('../dist/index'); // 1. Get audio URL const url = googleTTS.getAudioUrl('你好世界', { lang: 'zh-TW' }); console.log({ url }); // https://translate.google.com/translate_tts?... // 2. Get base64 text googleTTS .getAudioBase64('你好世界', { lang: 'zh-TW' }) .then((base64) => { console.log({ base64 }); // Save the audio file const buffer = Buffer.from(base64, 'base64'); fs.writeFileSync('hello-world-chinese.mp3', buffer, { encoding: 'base64' }); }) .catch(console.error);