Skip to content

Instantly share code, notes, and snippets.

@JoeThunyathep
Last active April 11, 2020 18:14
Show Gist options
  • Save JoeThunyathep/0c67eea5cc49fb407f8dbd59155e7ea2 to your computer and use it in GitHub Desktop.
Save JoeThunyathep/0c67eea5cc49fb407f8dbd59155e7ea2 to your computer and use it in GitHub Desktop.
Text2Speech.js
const textToSpeech = require('@google-cloud/text-to-speech');
const fs = require('fs');
const util = require('util');
const projectId = 'patrikhornak'
const keyFilename = 'patrikhornak-1f5ece28af9f.json'
const client = new textToSpeech.TextToSpeechClient({ projectId, keyFilename });
const YourSetting = fs.readFileSync('setting.json');
async function Text2Speech(YourSetting) {
const [response] = await client.synthesizeSpeech(JSON.parse(YourSetting));
const writeFile = util.promisify(fs.writeFile);
await writeFile(JSON.parse(YourSetting).outputFileName, response.audioContent, 'binary');
console.log(`Audio content written to file: ${JSON.parse(YourSetting).outputFileName}`);
}
Text2Speech(YourSetting);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment