Class v1.TextToSpeechClient (5.8.0)

Service that implements Google Cloud Text-to-Speech API. v1

Package

@google-cloud/text-to-speech

Constructors

(constructor)(opts, gaxInstance)

constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback);

Construct an instance of TextToSpeechClient.

Parameters
Name Description
opts ClientOptions
gaxInstance typeof gax | typeof fallback

: loaded instance of google-gax. Useful if you need to avoid loading the default gRPC version and want to use the fallback HTTP implementation. Load only fallback version and pass it to the constructor: ``` const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC const client = new TextToSpeechClient({fallback: true}, gax); ```

Properties

apiEndpoint

get apiEndpoint(): string;

The DNS address for this API service.

apiEndpoint

static get apiEndpoint(): string;

The DNS address for this API service - same as servicePath.

auth

auth: gax.GoogleAuth;

descriptors

descriptors: Descriptors;

innerApiCalls

innerApiCalls: {
        [name: string]: Function;
    };

pathTemplates

pathTemplates: {
        [name: string]: gax.PathTemplate;
    };

port

static get port(): number;

The port for this API service.

scopes

static get scopes(): string[];

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static get servicePath(): string;

The DNS address for this API service.

textToSpeechStub

textToSpeechStub?: Promise<{
        [name: string]: Function;
    }>;

universeDomain

get universeDomain(): string;

warn

warn: (code: string, message: string, warnType?: string) => void;

Methods

close()

close(): Promise<void>;

Terminate the gRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

Returns
Type Description
Promise<void>

{Promise} A promise that resolves when the client is closed.

getProjectId()

getProjectId(): Promise<string>;
Returns
Type Description
Promise<string>

getProjectId(callback)

getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter
Name Description
callback Callback<string, undefined, undefined>
Returns
Type Description
void

initialize()

initialize(): Promise<{
        [name: string]: Function;
    }>;

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

Returns
Type Description
Promise<{ [name: string]: Function; }>

{Promise} A promise that resolves to an authenticated service stub.

listVoices(request, options)

listVoices(request?: protos.google.cloud.texttospeech.v1.IListVoicesRequest, options?: CallOptions): Promise<[
        protos.google.cloud.texttospeech.v1.IListVoicesResponse,
        protos.google.cloud.texttospeech.v1.IListVoicesRequest | undefined,
        {} | undefined
    ]>;

Returns a list of Voice supported for synthesis.

Parameters
Name Description
request IListVoicesRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.cloud.texttospeech.v1.IListVoicesResponse, protos.google.cloud.texttospeech.v1.IListVoicesRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing ListVoicesResponse. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Optional. Recommended.
   *  BCP-47 (https://www.rfc-editor.org/rfc/bcp/bcp47.txt) language tag.
   *  If not specified, the API will return all supported voices.
   *  If specified, the ListVoices call will only return voices that can be used
   *  to synthesize this language_code. For example, if you specify `"en-NZ"`,
   *  all `"en-NZ"` voices will be returned. If you specify `"no"`, both
   *  `"no-\*"` (Norwegian) and `"nb-\*"` (Norwegian Bokmal) voices will be
   *  returned.
   */
  // const languageCode = 'abc123'

  // Imports the Texttospeech library
  const {TextToSpeechClient} = require('@google-cloud/text-to-speech').v1;

  // Instantiates a client
  const texttospeechClient = new TextToSpeechClient();

  async function callListVoices() {
    // Construct request
    const request = {
    };

    // Run request
    const response = await texttospeechClient.listVoices(request);
    console.log(response);
  }

  callListVoices();

listVoices(request, options, callback)

listVoices(request: protos.google.cloud.texttospeech.v1.IListVoicesRequest, options: CallOptions, callback: Callback<protos.google.cloud.texttospeech.v1.IListVoicesResponse, protos.google.cloud.texttospeech.v1.IListVoicesRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IListVoicesRequest
options CallOptions
callback Callback<protos.google.cloud.texttospeech.v1.IListVoicesResponse, protos.google.cloud.texttospeech.v1.IListVoicesRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

listVoices(request, callback)

listVoices(request: protos.google.cloud.texttospeech.v1.IListVoicesRequest, callback: Callback<protos.google.cloud.texttospeech.v1.IListVoicesResponse, protos.google.cloud.texttospeech.v1.IListVoicesRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IListVoicesRequest
callback Callback<protos.google.cloud.texttospeech.v1.IListVoicesResponse, protos.google.cloud.texttospeech.v1.IListVoicesRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

matchLocationFromModelName(modelName)

matchLocationFromModelName(modelName: string): string | number;

Parse the location from Model resource.

Parameter
Name Description
modelName string

A fully-qualified path representing Model resource.

Returns
Type Description
string | number

{string} A string representing the location.

matchModelFromModelName(modelName)

matchModelFromModelName(modelName: string): string | number;

Parse the model from Model resource.

Parameter
Name Description
modelName string

A fully-qualified path representing Model resource.

Returns
Type Description
string | number

{string} A string representing the model.

matchProjectFromModelName(modelName)

matchProjectFromModelName(modelName: string): string | number;

Parse the project from Model resource.

Parameter
Name Description
modelName string

A fully-qualified path representing Model resource.

Returns
Type Description
string | number

{string} A string representing the project.

modelPath(project, location, model)

modelPath(project: string, location: string, model: string): string;

Return a fully-qualified model resource name string.

Parameters
Name Description
project string
location string
model string
Returns
Type Description
string

{string} Resource name string.

streamingSynthesize(options)

streamingSynthesize(options?: CallOptions): gax.CancellableStream;

Performs bidirectional streaming speech synthesis: receive audio while sending text.

Parameter
Name Description
options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
gax.CancellableStream

{Stream} An object stream which is both readable and writable. It accepts objects representing StreamingSynthesizeRequest for write() method, and will emit objects representing StreamingSynthesizeResponse on 'data' event asynchronously. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  StreamingSynthesizeConfig to be used in this streaming attempt. Only
   *  specified in the first message sent in a `StreamingSynthesize` call.
   */
  // const streamingConfig = {}
  /**
   *  Input to synthesize. Specified in all messages but the first in a
   *  `StreamingSynthesize` call.
   */
  // const input = {}

  // Imports the Texttospeech library
  const {TextToSpeechClient} = require('@google-cloud/text-to-speech').v1;

  // Instantiates a client
  const texttospeechClient = new TextToSpeechClient();

  async function callStreamingSynthesize() {
    // Construct request
    const request = {
    };

    // Run request
    const stream = await texttospeechClient.streamingSynthesize();
    stream.on('data', (response) => { console.log(response) });
    stream.on('error', (err) => { throw(err) });
    stream.on('end', () => { /* API call completed */ });
    stream.write(request);
    stream.end();
  }

  callStreamingSynthesize();

synthesizeSpeech(request, options)

synthesizeSpeech(request?: protos.google.cloud.texttospeech.v1.ISynthesizeSpeechRequest, options?: CallOptions): Promise<[
        protos.google.cloud.texttospeech.v1.ISynthesizeSpeechResponse,
        protos.google.cloud.texttospeech.v1.ISynthesizeSpeechRequest | undefined,
        {} | undefined
    ]>;

Synthesizes speech synchronously: receive results after all text input has been processed.

Parameters
Name Description
request ISynthesizeSpeechRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.cloud.texttospeech.v1.ISynthesizeSpeechResponse, protos.google.cloud.texttospeech.v1.ISynthesizeSpeechRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing SynthesizeSpeechResponse. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The Synthesizer requires either plain text or SSML as input.
   */
  // const input = {}
  /**
   *  Required. The desired voice of the synthesized audio.
   */
  // const voice = {}
  /**
   *  Required. The configuration of the synthesized audio.
   */
  // const audioConfig = {}
  /**
   *  Advanced voice options.
   */
  // const advancedVoiceOptions = {}

  // Imports the Texttospeech library
  const {TextToSpeechClient} = require('@google-cloud/text-to-speech').v1;

  // Instantiates a client
  const texttospeechClient = new TextToSpeechClient();

  async function callSynthesizeSpeech() {
    // Construct request
    const request = {
      input,
      voice,
      audioConfig,
    };

    // Run request
    const response = await texttospeechClient.synthesizeSpeech(request);
    console.log(response);
  }

  callSynthesizeSpeech();

synthesizeSpeech(request, options, callback)

synthesizeSpeech(request: protos.google.cloud.texttospeech.v1.ISynthesizeSpeechRequest, options: CallOptions, callback: Callback<protos.google.cloud.texttospeech.v1.ISynthesizeSpeechResponse, protos.google.cloud.texttospeech.v1.ISynthesizeSpeechRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request ISynthesizeSpeechRequest
options CallOptions
callback Callback<protos.google.cloud.texttospeech.v1.ISynthesizeSpeechResponse, protos.google.cloud.texttospeech.v1.ISynthesizeSpeechRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

synthesizeSpeech(request, callback)

synthesizeSpeech(request: protos.google.cloud.texttospeech.v1.ISynthesizeSpeechRequest, callback: Callback<protos.google.cloud.texttospeech.v1.ISynthesizeSpeechResponse, protos.google.cloud.texttospeech.v1.ISynthesizeSpeechRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request ISynthesizeSpeechRequest
callback Callback<protos.google.cloud.texttospeech.v1.ISynthesizeSpeechResponse, protos.google.cloud.texttospeech.v1.ISynthesizeSpeechRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void