Last active
April 11, 2020 18:14
-
-
Save JoeThunyathep/0c67eea5cc49fb407f8dbd59155e7ea2 to your computer and use it in GitHub Desktop.
Text2Speech.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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