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

Commit

Permalink
fix: "client already closed" error fires earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored and bcoe committed Jan 3, 2020
1 parent 1f6f4e5 commit 41b39bc
Show file tree
Hide file tree
Showing 8 changed files with 1,550 additions and 1,256 deletions.
1 change: 1 addition & 0 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"**/scripts",
"**/protos",
"**/test",
"**/*.d.ts",
".jsdoc.js",
"**/.jsdoc.js",
"karma.conf.js",
Expand Down
53 changes: 27 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,36 @@ npm install @google-cloud/text-to-speech
### Using the client library

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

// Import other required libraries
const fs = require('fs');
const util = require('util');
async function main() {
// Import other required libraries
const fs = require('fs');
const util = require('util');
// Creates a client
const client = new textToSpeech.TextToSpeechClient();

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

// Construct the request
const request = {
input: {text: text},
// Select the language and SSML Voice Gender (optional)
voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'},
// Select the type of audio encoding
audioConfig: {audioEncoding: 'MP3'},
};

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

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

// Construct the request
const request = {
input: {text: text},
// Select the language and SSML voice gender (optional)
voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'},
// select the type of audio encoding
audioConfig: {audioEncoding: 'MP3'},
};

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

```

Expand Down
2 changes: 1 addition & 1 deletion protos/protos.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion protos/protos.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions src/v1/text_to_speech_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ export class TextToSpeechClient {
for (const methodName of textToSpeechStubMethods) {
const innerCallPromise = this.textToSpeechStub.then(
stub => (...args: Array<{}>) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return stub[methodName].apply(stub, args);
},
(err: Error | null | undefined) => () => {
Expand All @@ -186,9 +189,6 @@ export class TextToSpeechClient {
callOptions?: CallOptions,
callback?: APICallback
) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return apiCall(argument, callOptions, callback);
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/v1beta1/text_to_speech_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ export class TextToSpeechClient {
for (const methodName of textToSpeechStubMethods) {
const innerCallPromise = this.textToSpeechStub.then(
stub => (...args: Array<{}>) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return stub[methodName].apply(stub, args);
},
(err: Error | null | undefined) => () => {
Expand All @@ -186,9 +189,6 @@ export class TextToSpeechClient {
callOptions?: CallOptions,
callback?: APICallback
) => {
if (this._terminated) {
return Promise.reject('The client has already been closed.');
}
return apiCall(argument, callOptions, callback);
};
}
Expand Down
Loading

0 comments on commit 41b39bc

Please sign in to comment.