MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / synthesizeSsmlFile

Function synthesizeSsmlFile

texttospeech/synthesize.js:96–121  ·  view source on GitHub ↗
(ssmlFile, outputFile)

Source from the content-addressed store, hash-verified

94}
95
96async 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
123async function main() {
124require(`yargs`) // eslint-disable-line

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected