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

Function main

texttospeech/quickstart.js:17–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function main() {
18 // [START tts_quickstart]
19 // Imports the Google Cloud client library
20 const textToSpeech = require('@google-cloud/text-to-speech');
21
22 // Import other required libraries
23 const {writeFile} = require('node:fs/promises');
24
25 // Creates a client
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]
51}
52
53main().catch(err => {
54 console.error(err);

Callers 1

quickstart.jsFile · 0.70

Calls 1

quickStartFunction · 0.70

Tested by

no test coverage detected