|
14 | 14 |
|
15 | 15 | 'use strict';
|
16 | 16 |
|
17 |
| -// [START tts_quickstart] |
18 |
| -// Imports the Google Cloud client library |
19 |
| -const textToSpeech = require('@google-cloud/text-to-speech'); |
| 17 | +function main( |
| 18 | +){ |
| 19 | + // [START tts_quickstart] |
| 20 | + // Imports the Google Cloud client library |
| 21 | + const textToSpeech = require('@google-cloud/text-to-speech'); |
20 | 22 |
|
21 |
| -// Import other required libraries |
22 |
| -const fs = require('fs'); |
23 |
| -const util = require('util'); |
24 |
| -async function main() { |
| 23 | + // Import other required libraries |
| 24 | + const fs = require('fs'); |
| 25 | + const util = require('util'); |
25 | 26 | // Creates a client
|
26 | 27 | const client = new textToSpeech.TextToSpeechClient();
|
| 28 | + async function quickStart() { |
27 | 29 |
|
28 |
| - // The text to synthesize |
29 |
| - const text = 'Hello, world!'; |
| 30 | + // The text to synthesize |
| 31 | + const text = 'hello, world!'; |
30 | 32 |
|
31 |
| - // Construct the request |
32 |
| - const request = { |
33 |
| - input: {text: text}, |
34 |
| - // Select the language and SSML Voice Gender (optional) |
35 |
| - voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'}, |
36 |
| - // Select the type of audio encoding |
37 |
| - audioConfig: {audioEncoding: 'MP3'}, |
38 |
| - }; |
| 33 | + // Construct the request |
| 34 | + const request = { |
| 35 | + input: {text: text}, |
| 36 | + // Select the language and SSML voice gender (optional) |
| 37 | + voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'}, |
| 38 | + // select the type of audio encoding |
| 39 | + audioConfig: {audioEncoding: 'MP3'}, |
| 40 | + }; |
39 | 41 |
|
40 |
| - // Performs the Text-to-Speech request |
41 |
| - const [response] = await client.synthesizeSpeech(request); |
42 |
| - // Write the binary audio content to a local file |
43 |
| - const writeFile = util.promisify(fs.writeFile); |
44 |
| - await writeFile('output.mp3', response.audioContent, 'binary'); |
45 |
| - console.log('Audio content written to file: output.mp3'); |
| 42 | + // Performs the text-to-speech request |
| 43 | + const [response] = await client.synthesizeSpeech(request); |
| 44 | + // Write the binary audio content to a local file |
| 45 | + const writeFile = util.promisify(fs.writeFile); |
| 46 | + await writeFile('output.mp3', response.audioContent, 'binary'); |
| 47 | + console.log('Audio content written to file: output.mp3'); |
| 48 | + } |
| 49 | + quickStart(); |
| 50 | + // [END tts_quickstart] |
46 | 51 | }
|
47 |
| -// [END tts_quickstart] |
48 |
| -main().catch(console.error); |
| 52 | + |
| 53 | +main(...process.argv.slice(2)); |
0 commit comments