Skip to content

Commit 7d45732

Browse files
leahecoleBenjamin E. Coe
andauthored
fix: move region tag to encompass catch (#320)
* fix: move region tag to encompass catch * fix: refactor to adhere to sample policies * fix: revert weird lowercases * fix: another stupid lowercase Co-authored-by: Benjamin E. Coe <bencoe@google.com>
1 parent 63f14d9 commit 7d45732

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

texttospeech/quickstart.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,40 @@
1414

1515
'use strict';
1616

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');
2022

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');
2526
// Creates a client
2627
const client = new textToSpeech.TextToSpeechClient();
28+
async function quickStart() {
2729

28-
// The text to synthesize
29-
const text = 'Hello, world!';
30+
// The text to synthesize
31+
const text = 'hello, world!';
3032

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+
};
3941

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]
4651
}
47-
// [END tts_quickstart]
48-
main().catch(console.error);
52+
53+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)