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

Function main

texttospeech/quickstart.mjs:18–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16import {TextToSpeechClient} from '@google-cloud/text-to-speech';
17
18async function main() {
19 // Create a Text-to-Speech client instance
20 const client = new TextToSpeechClient();
21
22 // The text that should be converted to speech
23 const text = 'hello, world!';
24
25 const outputFile = 'quickstart_output.mp3';
26
27 // Configure the text-to-speech request
28 const request = {
29 input: {text},
30 // Select the language and SSML voice gender (optional)
31 voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'},
32 // Configure the audio format of the output
33 audioConfig: {audioEncoding: 'MP3'},
34 };
35
36 // Performs the text-to-speech request
37 const [response] = await client.synthesizeSpeech(request);
38
39 // Save the generated binary audio content to a local file
40 await writeFile(outputFile, response.audioContent, 'binary');
41 console.log(`Audio content written to file: ${outputFile}`);
42}
43
44main().catch(err => {
45 console.error(err);

Callers 1

quickstart.mjsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected