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

Function synthesizeSsml

texttospeech/synthesize.js:42–67  ·  view source on GitHub ↗
(ssml, outputFile)

Source from the content-addressed store, hash-verified

40}
41
42async function synthesizeSsml(ssml, outputFile) {
43 // [START tts_synthesize_ssml]
44 const textToSpeech = require('@google-cloud/text-to-speech');
45 const fs = require('fs');
46 const util = require('util');
47
48 const client = new textToSpeech.TextToSpeechClient();
49
50 /**
51 * TODO(developer): Uncomment the following lines before running the sample.
52 */
53 // const ssml = '<speak>Hello there.</speak>';
54 // const outputFile = 'Local path to save audio file to, e.g. output.mp3';
55
56 const request = {
57 input: {ssml: ssml},
58 voice: {languageCode: 'en-US', ssmlGender: 'FEMALE'},
59 audioConfig: {audioEncoding: 'MP3'},
60 };
61
62 const [response] = await client.synthesizeSpeech(request);
63 const writeFile = util.promisify(fs.writeFile);
64 await writeFile(outputFile, response.audioContent, 'binary');
65 console.log(`Audio content written to file: ${outputFile}`);
66 // [END tts_synthesize_ssml]
67}
68
69async function synthesizeTextFile(textFile, outputFile) {
70 // [START tts_synthesize_text_file]

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected