| 94 | } |
| 95 | |
| 96 | async function synthesizeSsmlFile(ssmlFile, outputFile) { |
| 97 | // [START tts_synthesize_ssml_file] |
| 98 | const textToSpeech = require('@google-cloud/text-to-speech'); |
| 99 | const fs = require('fs'); |
| 100 | const util = require('util'); |
| 101 | |
| 102 | const client = new textToSpeech.TextToSpeechClient(); |
| 103 | |
| 104 | /** |
| 105 | * TODO(developer): Uncomment the following lines before running the sample. |
| 106 | */ |
| 107 | // const ssmlFile = 'Local path to SSML file, eg. input.ssml'; |
| 108 | // const outputFile = 'Local path to save audio file to, e.g. output.mp3'; |
| 109 | |
| 110 | const request = { |
| 111 | input: {ssml: fs.readFileSync(ssmlFile)}, |
| 112 | voice: {languageCode: 'en-US', ssmlGender: 'FEMALE'}, |
| 113 | audioConfig: {audioEncoding: 'MP3'}, |
| 114 | }; |
| 115 | |
| 116 | const [response] = await client.synthesizeSpeech(request); |
| 117 | const writeFile = util.promisify(fs.writeFile); |
| 118 | await writeFile(outputFile, response.audioContent, 'binary'); |
| 119 | console.log(`Audio content written to file: ${outputFile}`); |
| 120 | // [END tts_synthesize_ssml_file] |
| 121 | } |
| 122 | |
| 123 | async function main() { |
| 124 | require(`yargs`) // eslint-disable-line |