Class v1beta1.TextToSpeechClient (5.0.2)

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

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
NameDescription
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

static get apiEndpoint(): string;

The DNS address for this API service - same as servicePath(), exists for compatibility reasons.

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

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
TypeDescription
Promise<void>

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

getProjectId()

getProjectId(): Promise<string>;
Returns
TypeDescription
Promise<string>

getProjectId(callback)

getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter
NameDescription
callback Callback<string, undefined, undefined>
Returns
TypeDescription
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
TypeDescription
Promise<{ [name: string]: Function; }>

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

listVoices(request, options)

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

Returns a list of Voice supported for synthesis.

Parameters
NameDescription
request IListVoicesRequest

The request object that will be sent.

options gax.CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.cloud.texttospeech.v1beta1.IListVoicesResponse, protos.google.cloud.texttospeech.v1beta1.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').v1beta1;

  // 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.v1beta1.IListVoicesRequest, options: CallOptions, callback: Callback<protos.google.cloud.texttospeech.v1beta1.IListVoicesResponse, protos.google.cloud.texttospeech.v1beta1.IListVoicesRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IListVoicesRequest
options gax.CallOptions
callback Callback<protos.google.cloud.texttospeech.v1beta1.IListVoicesResponse, protos.google.cloud.texttospeech.v1beta1.IListVoicesRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

listVoices(request, callback)

listVoices(request: protos.google.cloud.texttospeech.v1beta1.IListVoicesRequest, callback: Callback<protos.google.cloud.texttospeech.v1beta1.IListVoicesResponse, protos.google.cloud.texttospeech.v1beta1.IListVoicesRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IListVoicesRequest
callback Callback<protos.google.cloud.texttospeech.v1beta1.IListVoicesResponse, protos.google.cloud.texttospeech.v1beta1.IListVoicesRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

matchLocationFromModelName(modelName)

matchLocationFromModelName(modelName: string): string | number;

Parse the location from Model resource.

Parameter
NameDescription
modelName string

A fully-qualified path representing Model resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchModelFromModelName(modelName)

matchModelFromModelName(modelName: string): string | number;

Parse the model from Model resource.

Parameter
NameDescription
modelName string

A fully-qualified path representing Model resource.

Returns
TypeDescription
string | number

{string} A string representing the model.

matchProjectFromModelName(modelName)

matchProjectFromModelName(modelName: string): string | number;

Parse the project from Model resource.

Parameter
NameDescription
modelName string

A fully-qualified path representing Model resource.

Returns
TypeDescription
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
NameDescription
project string
location string
model string
Returns
TypeDescription
string

{string} Resource name string.

synthesizeSpeech(request, options)

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

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

Parameters
NameDescription
request ISynthesizeSpeechRequest

The request object that will be sent.

options gax.CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.cloud.texttospeech.v1beta1.ISynthesizeSpeechResponse, (protos.google.cloud.texttospeech.v1beta1.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 = {}
  /**
   *  Whether and what timepoints are returned in the response.
   */
  // const enableTimePointing = [1,2,3,4]

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

  // 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.v1beta1.ISynthesizeSpeechRequest, options: CallOptions, callback: Callback<protos.google.cloud.texttospeech.v1beta1.ISynthesizeSpeechResponse, protos.google.cloud.texttospeech.v1beta1.ISynthesizeSpeechRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request ISynthesizeSpeechRequest
options gax.CallOptions
callback Callback<protos.google.cloud.texttospeech.v1beta1.ISynthesizeSpeechResponse, protos.google.cloud.texttospeech.v1beta1.ISynthesizeSpeechRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

synthesizeSpeech(request, callback)

synthesizeSpeech(request: protos.google.cloud.texttospeech.v1beta1.ISynthesizeSpeechRequest, callback: Callback<protos.google.cloud.texttospeech.v1beta1.ISynthesizeSpeechResponse, protos.google.cloud.texttospeech.v1beta1.ISynthesizeSpeechRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request ISynthesizeSpeechRequest
callback Callback<protos.google.cloud.texttospeech.v1beta1.ISynthesizeSpeechResponse, protos.google.cloud.texttospeech.v1beta1.ISynthesizeSpeechRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void