Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
implemented changes requested for PR!
Browse files Browse the repository at this point in the history
  • Loading branch information
Praveen Kumar Singh committed Nov 12, 2018
1 parent 307330f commit 1958d6a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 71 deletions.
25 changes: 10 additions & 15 deletions samples/audioProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@
*/

'use strict';
function synthesizeSpeechAsync(request = {}) {
// Imports the Google Cloud client library
const textToSpeech = require('@google-cloud/text-to-speech');
// Creates a client
const client = new textToSpeech.TextToSpeechClient();
return new Promise((resolve, reject) => {
client.synthesizeSpeech(request, (err, response) => {
if (err) reject(err);
else resolve(response);
});
});
}

async function synthesizeText(
text,
outputFile,
Expand All @@ -35,16 +22,24 @@ async function synthesizeText(
ssmlGender
) {
//[START tts_synthesize_text_audio_profile_beta]

// Imports the Google Cloud client library
const speech = require('@google-cloud/text-to-speech');
const fs = require('fs');
const util = require('util');

// Creates a client
const client = new speech.TextToSpeechClient();

const request = {
input: {text: text},
voice: {languageCode: languageCode, ssmlGender: ssmlGender},
audioConfig: {audioEncoding: 'MP3', effectsProfileId: effectsProfileId},
};

const response = await synthesizeSpeechAsync(request);
fs.writeFileSync(outputFile, response.audioContent, 'binary');
const [response] = await client.synthesizeSpeech(request);
const writeFile = util.promisify(fs.writeFile);
await writeFile(outputFile, response.audioContent, 'binary');
console.log(`Audio content written to file: ${outputFile}`);
// [END tts_synthesize_text_audio_profile_beta]
}
Expand Down
50 changes: 19 additions & 31 deletions samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,20 @@

'use strict';

// [START tts_quickstart]
const fs = require('fs');

// Imports the Google Cloud client library
const textToSpeech = require('@google-cloud/text-to-speech');

// Creates a client
const client = new textToSpeech.TextToSpeechClient();

// The text to synthesize
const text = 'Hello, world!';

function synthesizeSpeech(request = {}) {
return new Promise((resolve, reject) => {
// Performs the Text-to-Speech request
client.synthesizeSpeech(request, (err, response) => {
if (err) {
reject(err);
} else {
resolve(response);
}
});
});
}

async function main() {
// [START tts_quickstart]
const fs = require('fs');
const util = require('util');

// Imports the Google Cloud client library
const textToSpeech = require('@google-cloud/text-to-speech');

// Creates a client
const client = new textToSpeech.TextToSpeechClient();

// The text to synthesize
const text = 'Hello, world!';

// Construct the request
const request = {
input: {text: text},
Expand All @@ -50,13 +38,13 @@ async function main() {
audioConfig: {audioEncoding: 'MP3'},
};

const response = await synthesizeSpeech(request);
// Performs the Text-to-Speech request
const [response] = await client.synthesizeSpeech(request);
// Write the binary audio content to a local file
fs.writeFileSync('output.mp3', response.audioContent, 'binary');
const writeFile = util.promisify(fs.writeFile);
await writeFile('output.mp3', response.audioContent, 'binary');
console.log('Audio content written to file: output.mp3');
// [END tts_quickstart]
}

main().catch(err => {
console.log(err);
});
// [END tts_quickstart]
main().catch(console.error);
53 changes: 28 additions & 25 deletions samples/synthesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,13 @@
*/

'use strict';
function synthesizeSpeechAsync(request = {}) {
// Imports the Google Cloud client library
const textToSpeech = require('@google-cloud/text-to-speech');
// Creates a client
const client = new textToSpeech.TextToSpeechClient();
return new Promise((resolve, reject) => {
client.synthesizeSpeech(request, (err, response) => {
if (err) reject(err);
else resolve(response);
});
});
}

async function synthesizeText(text, outputFile) {
// [START tts_synthesize_text]
const textToSpeech = require('@google-cloud/text-to-speech');
const fs = require('fs');
const util = require('util');

const client = new textToSpeech.TextToSpeechClient();

/**
* TODO(developer): Uncomment the following lines before running the sample.
Expand All @@ -42,16 +33,20 @@ async function synthesizeText(text, outputFile) {
voice: {languageCode: 'en-US', ssmlGender: 'FEMALE'},
audioConfig: {audioEncoding: 'MP3'},
};
const response = await synthesizeSpeechAsync(request);
fs.writeFileSync(outputFile, response.audioContent, 'binary');
const [response] = await client.synthesizeSpeech(request);
const writeFile = util.promisify(fs.writeFile);
await writeFile(outputFile, response.audioContent, 'binary');
console.log(`Audio content written to file: ${outputFile}`);
// [END tts_synthesize_text]
}

async function synthesizeSsml(ssml, outputFile) {
// [START tts_synthesize_ssml]

const textToSpeech = require('@google-cloud/text-to-speech');
const fs = require('fs');
const util = require('util');

const client = new textToSpeech.TextToSpeechClient();

/**
* TODO(developer): Uncomment the following lines before running the sample.
Expand All @@ -65,16 +60,20 @@ async function synthesizeSsml(ssml, outputFile) {
audioConfig: {audioEncoding: 'MP3'},
};

const response = await synthesizeSpeechAsync(request);

fs.writeFileSync(outputFile, response.audioContent, 'binary');
const [response] = await client.synthesizeSpeech(request);
const writeFile = util.promisify(fs.writeFile);
await writeFile(outputFile, response.audioContent, 'binary');
console.log(`Audio content written to file: ${outputFile}`);
// [END tts_synthesize_ssml]
}

async function synthesizeTextFile(textFile, outputFile) {
// [START tts_synthesize_text_file]
const textToSpeech = require('@google-cloud/text-to-speech');
const fs = require('fs');
const util = require('util');

const client = new textToSpeech.TextToSpeechClient();

/**
* TODO(developer): Uncomment the following lines before running the sample.
Expand All @@ -88,16 +87,20 @@ async function synthesizeTextFile(textFile, outputFile) {
audioConfig: {audioEncoding: 'MP3'},
};

const response = await synthesizeSpeechAsync(request);

fs.writeFileSync(outputFile, response.audioContent, 'binary');
const [response] = await client.synthesizeSpeech(request);
const writeFile = util.promisify(fs.writeFile);
await writeFile(outputFile, response.audioContent, 'binary');
console.log(`Audio content written to file: ${outputFile}`);
// [END tts_synthesize_text_file]
}

async function synthesizeSsmlFile(ssmlFile, outputFile) {
// [START tts_synthesize_ssml_file]
const textToSpeech = require('@google-cloud/text-to-speech');
const fs = require('fs');
const util = require('util');

const client = new textToSpeech.TextToSpeechClient();

/**
* TODO(developer): Uncomment the following lines before running the sample.
Expand All @@ -111,9 +114,9 @@ async function synthesizeSsmlFile(ssmlFile, outputFile) {
audioConfig: {audioEncoding: 'MP3'},
};

const response = await synthesizeSpeechAsync(request);

fs.writeFileSync(outputFile, response.audioContent, 'binary');
const [response] = await client.synthesizeSpeech(request);
const writeFile = util.promisify(fs.writeFile);
await writeFile(outputFile, response.audioContent, 'binary');
console.log(`Audio content written to file: ${outputFile}`);
// [END tts_synthesize_ssml_file]
}
Expand Down

0 comments on commit 1958d6a

Please sign in to comment.