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

Function quickStart

texttospeech/quickstart.js:28–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26 const client = new textToSpeech.TextToSpeechClient();
27
28 async function quickStart() {
29 // The text to synthesize
30 const text = 'hello, world!';
31
32 // Construct the request
33 const request = {
34 input: {text: text},
35 // Select the language and SSML voice gender (optional)
36 voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'},
37 // select the type of audio encoding
38 audioConfig: {audioEncoding: 'MP3'},
39 };
40
41 // Performs the text-to-speech request
42 const [response] = await client.synthesizeSpeech(request);
43
44 // Save the generated binary audio content to a local file
45 await writeFile('output.mp3', response.audioContent, 'binary');
46 console.log('Audio content written to file: output.mp3');
47 }
48
49 await quickStart();
50 // [END tts_quickstart]

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected