Client for Google Cloud Texttospeech API

class google.cloud.texttospeech_v1beta1.AudioConfig(mapping=None, *, ignore_unknown_fields=False, **kwargs)

Description of audio data to be synthesized.

audio_encoding()

Required. The format of the audio byte stream.

  • Type

    AudioEncoding

speaking_rate()

Optional. Input only. Speaking rate/speed, in the range [0.25, 4.0]. 1.0 is the normal native speed supported by the specific voice. 2.0 is twice as fast, and 0.5 is half as fast. If unset(0.0), defaults to the native 1.0 speed. Any other values < 0.25 or > 4.0 will return an error.

pitch()

Optional. Input only. Speaking pitch, in the range [-20.0, 20.0]. 20 means increase 20 semitones from the original pitch. -20 means decrease 20 semitones from the original pitch.

volume_gain_db()

Optional. Input only. Volume gain (in dB) of the normal native volume supported by the specific voice, in the range [-96.0, 16.0]. If unset, or set to a value of 0.0 (dB), will play at normal native signal amplitude. A value of -6.0 (dB) will play at approximately half the amplitude of the normal native signal amplitude. A value of +6.0 (dB) will play at approximately twice the amplitude of the normal native signal amplitude. Strongly recommend not to exceed +10 (dB) as there’s usually no effective increase in loudness for any value greater than that.

sample_rate_hertz()

Optional. The synthesis sample rate (in hertz) for this audio. When this is specified in SynthesizeSpeechRequest, if this is different from the voice’s natural sample rate, then the synthesizer will honor this request by converting to the desired sample rate (which might result in worse audio quality), unless the specified sample rate is not supported for the encoding chosen, in which case it will fail the request and return [google.rpc.Code.INVALID_ARGUMENT][].

effects_profile_id()

Optional. Input only. An identifier which selects ‘audio effects’ profiles that are applied on (post synthesized) text to speech. Effects are applied on top of each other in the order they are given. See audio profiles for current supported profile ids.

  • Type

    Sequence[str]

_delattr_(key)

Delete the value on the given field.

This is generally equivalent to setting a falsy value.

_eq_(other)

Return True if the messages are equal, False otherwise.

_ne_(other)

Return True if the messages are unequal, False otherwise.

_setattr_(key, value)

Set the value on the given field.

For well-known protocol buffer types which are marshalled, either the protocol buffer object or the Python equivalent is accepted.

class google.cloud.texttospeech_v1beta1.AudioEncoding(value)

Configuration to set up audio encoder. The encoding determines the output audio format that we’d like.

class google.cloud.texttospeech_v1beta1.ListVoicesRequest(mapping=None, *, ignore_unknown_fields=False, **kwargs)

The top-level message sent by the client for the ListVoices method.

language_code()

Optional. Recommended. BCP-47 language tag. If specified, the ListVoices call will only return voices that can be used to synthesize this language_code. E.g. when specifying “en-NZ”, you will get supported “en-*” voices; when specifying “no”, you will get supported “no-*” (Norwegian) and “nb-” (Norwegian Bokmal) voices; specifying “zh” will also get supported “cmn-” voices; specifying “zh-hk” will also get supported “yue-*” voices.

_delattr_(key)

Delete the value on the given field.

This is generally equivalent to setting a falsy value.

_eq_(other)

Return True if the messages are equal, False otherwise.

_ne_(other)

Return True if the messages are unequal, False otherwise.

_setattr_(key, value)

Set the value on the given field.

For well-known protocol buffer types which are marshalled, either the protocol buffer object or the Python equivalent is accepted.

class google.cloud.texttospeech_v1beta1.ListVoicesResponse(mapping=None, *, ignore_unknown_fields=False, **kwargs)

The message returned to the client by the ListVoices method.

voices()

The list of voices.

  • Type

    Sequence[Voice]

_delattr_(key)

Delete the value on the given field.

This is generally equivalent to setting a falsy value.

_eq_(other)

Return True if the messages are equal, False otherwise.

_ne_(other)

Return True if the messages are unequal, False otherwise.

_setattr_(key, value)

Set the value on the given field.

For well-known protocol buffer types which are marshalled, either the protocol buffer object or the Python equivalent is accepted.

class google.cloud.texttospeech_v1beta1.SsmlVoiceGender(value)

Gender of the voice as described in SSML voice element.

class google.cloud.texttospeech_v1beta1.SynthesisInput(mapping=None, *, ignore_unknown_fields=False, **kwargs)

Contains text input to be synthesized. Either text or ssml must be supplied. Supplying both or neither returns [google.rpc.Code.INVALID_ARGUMENT][]. The input size is limited to 5000 characters.

text()

The raw text to be synthesized.

ssml()

The SSML document to be synthesized. The SSML document must be valid and well-formed. Otherwise the RPC will fail and return [google.rpc.Code.INVALID_ARGUMENT][]. For more information, see SSML.

_delattr_(key)

Delete the value on the given field.

This is generally equivalent to setting a falsy value.

_eq_(other)

Return True if the messages are equal, False otherwise.

_ne_(other)

Return True if the messages are unequal, False otherwise.

_setattr_(key, value)

Set the value on the given field.

For well-known protocol buffer types which are marshalled, either the protocol buffer object or the Python equivalent is accepted.

class google.cloud.texttospeech_v1beta1.SynthesizeSpeechRequest(mapping=None, *, ignore_unknown_fields=False, **kwargs)

The top-level message sent by the client for the SynthesizeSpeech method.

input()

Required. The Synthesizer requires either plain text or SSML as input.

  • Type

    SynthesisInput

voice()

Required. The desired voice of the synthesized audio.

  • Type

    VoiceSelectionParams

audio_config()

Required. The configuration of the synthesized audio.

  • Type

    AudioConfig

_delattr_(key)

Delete the value on the given field.

This is generally equivalent to setting a falsy value.

_eq_(other)

Return True if the messages are equal, False otherwise.

_ne_(other)

Return True if the messages are unequal, False otherwise.

_setattr_(key, value)

Set the value on the given field.

For well-known protocol buffer types which are marshalled, either the protocol buffer object or the Python equivalent is accepted.

class google.cloud.texttospeech_v1beta1.SynthesizeSpeechResponse(mapping=None, *, ignore_unknown_fields=False, **kwargs)

The message returned to the client by the SynthesizeSpeech method.

audio_content()

The audio data bytes encoded as specified in the request, including the header for encodings that are wrapped in containers (e.g. MP3, OGG_OPUS). For LINEAR16 audio, we include the WAV header. Note: as with all bytes fields, protobuffers use a pure binary representation, whereas JSON representations use base64.

_delattr_(key)

Delete the value on the given field.

This is generally equivalent to setting a falsy value.

_eq_(other)

Return True if the messages are equal, False otherwise.

_ne_(other)

Return True if the messages are unequal, False otherwise.

_setattr_(key, value)

Set the value on the given field.

For well-known protocol buffer types which are marshalled, either the protocol buffer object or the Python equivalent is accepted.

class google.cloud.texttospeech_v1beta1.TextToSpeechClient(*, credentials: google.auth.credentials.Credentials = None, transport: Union[str, google.cloud.texttospeech_v1beta1.services.text_to_speech.transports.base.TextToSpeechTransport] = None, client_options: <module 'google.api_core.client_options' from '/workspace/python-texttospeech/.nox/docfx/lib/python3.9/site-packages/google/api_core/client_options.py'> = None)

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

Instantiate the text to speech client.

  • Parameters

    • credentials (Optional[google.auth.credentials.Credentials]) – The authorization credentials to attach to requests. These credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment.

    • transport (Union[str, **TextToSpeechTransport]) – The transport to use. If set to None, a transport is chosen automatically.

    • client_options (ClientOptions) – Custom options for the client. (1) The api_endpoint property can be used to override the default endpoint provided by the client. (2) If transport argument is None, client_options can be used to create a mutual TLS transport. If client_cert_source is provided, mutual TLS transport will be created with the given api_endpoint or the default mTLS endpoint, and the client SSL credentials obtained from client_cert_source.

  • Raises

    google.auth.exceptions.MutualTlsChannelError – If mutual TLS transport creation failed for any reason.

classmethod from_service_account_file(filename: str, *args, **kwargs)

Creates an instance of this client using the provided credentials file.

  • Parameters

    • filename (str) – The path to the service account private key json file.

    • args – Additional arguments to pass to the constructor.

    • kwargs – Additional arguments to pass to the constructor.

  • Returns

    The constructed client.

  • Return type

    {@api.name}

classmethod from_service_account_json(filename: str, *args, **kwargs)

Creates an instance of this client using the provided credentials file.

  • Parameters

    • filename (str) – The path to the service account private key json file.

    • args – Additional arguments to pass to the constructor.

    • kwargs – Additional arguments to pass to the constructor.

  • Returns

    The constructed client.

  • Return type

    {@api.name}

list_voices(request: Optional[google.cloud.texttospeech_v1beta1.types.cloud_tts.ListVoicesRequest] = None, *, language_code: Optional[str] = None, retry: google.api_core.retry.Retry = <_MethodDefault._DEFAULT_VALUE:

Returns a list of Voice supported for synthesis.

  • Parameters

    • request (ListVoicesRequest) – The request object. The top-level message sent by the client for the ListVoices method.

    • language_code (str) – Optional. Recommended. BCP-47 language tag. If specified, the ListVoices call will only return voices that can be used to synthesize this language_code. E.g. when specifying “en-NZ”, you will get supported “en-*” voices; when specifying “no”, you will get supported “no-*” (Norwegian) and “nb-” (Norwegian Bokmal) voices; specifying “zh” will also get supported “cmn-” voices; specifying “zh-hk” will also get supported “yue-*” voices. This corresponds to the language_code field on the request instance; if request is provided, this should not be set.

    • retry (google.api_core.retry.Retry) – Designation of what errors, if any, should be retried.

    • timeout (float) – The timeout for this request.

    • metadata (Sequence[Tuple[str, *[str](https://python.readthedocs.io/en/latest/library/stdtypes.html#str)]*]) – Strings which should be sent along with the request as metadata.

  • Returns

    The message returned to the client by the ListVoices method.

  • Return type

    ListVoicesResponse

synthesize_speech(request: Optional[google.cloud.texttospeech_v1beta1.types.cloud_tts.SynthesizeSpeechRequest] = None, *, input: Optional[google.cloud.texttospeech_v1beta1.types.cloud_tts.SynthesisInput] = None, voice: Optional[google.cloud.texttospeech_v1beta1.types.cloud_tts.VoiceSelectionParams] = None, audio_config: Optional[google.cloud.texttospeech_v1beta1.types.cloud_tts.AudioConfig] = None, retry: google.api_core.retry.Retry = <_MethodDefault._DEFAULT_VALUE:

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

  • Parameters

    • request (SynthesizeSpeechRequest) – The request object. The top-level message sent by the client for the SynthesizeSpeech method.

    • input (SynthesisInput) – Required. The Synthesizer requires either plain text or SSML as input. This corresponds to the input field on the request instance; if request is provided, this should not be set.

    • voice (VoiceSelectionParams) – Required. The desired voice of the synthesized audio. This corresponds to the voice field on the request instance; if request is provided, this should not be set.

    • audio_config (AudioConfig) – Required. The configuration of the synthesized audio. This corresponds to the audio_config field on the request instance; if request is provided, this should not be set.

    • retry (google.api_core.retry.Retry) – Designation of what errors, if any, should be retried.

    • timeout (float) – The timeout for this request.

    • metadata (Sequence[Tuple[str, *[str](https://python.readthedocs.io/en/latest/library/stdtypes.html#str)]*]) – Strings which should be sent along with the request as metadata.

  • Returns

    The message returned to the client by the SynthesizeSpeech method.

  • Return type

    SynthesizeSpeechResponse

class google.cloud.texttospeech_v1beta1.Voice(mapping=None, *, ignore_unknown_fields=False, **kwargs)

Description of a voice supported by the TTS service.

language_codes()

The languages that this voice supports, expressed as BCP-47 language tags (e.g. “en-US”, “es-419”, “cmn-tw”).

  • Type

    Sequence[str]

name()

The name of this voice. Each distinct voice has a unique name.

ssml_gender()

The gender of this voice.

  • Type

    SsmlVoiceGender

natural_sample_rate_hertz()

The natural sample rate (in hertz) for this voice.

_delattr_(key)

Delete the value on the given field.

This is generally equivalent to setting a falsy value.

_eq_(other)

Return True if the messages are equal, False otherwise.

_ne_(other)

Return True if the messages are unequal, False otherwise.

_setattr_(key, value)

Set the value on the given field.

For well-known protocol buffer types which are marshalled, either the protocol buffer object or the Python equivalent is accepted.

class google.cloud.texttospeech_v1beta1.VoiceSelectionParams(mapping=None, *, ignore_unknown_fields=False, **kwargs)

Description of which voice to use for a synthesis request.

language_code()

Required. The language (and potentially also the region) of the voice expressed as a BCP-47 language tag, e.g. “en-US”. This should not include a script tag (e.g. use “cmn-cn” rather than “cmn-Hant-cn”), because the script will be inferred from the input provided in the SynthesisInput. The TTS service will use this parameter to help choose an appropriate voice. Note that the TTS service may choose a voice with a slightly different language code than the one selected; it may substitute a different region (e.g. using en-US rather than en-CA if there isn’t a Canadian voice available), or even a different language, e.g. using “nb” (Norwegian Bokmal) instead of “no” (Norwegian)”.

name()

The name of the voice. If not set, the service will choose a voice based on the other parameters such as language_code and gender.

ssml_gender()

The preferred gender of the voice. If not set, the service will choose a voice based on the other parameters such as language_code and name. Note that this is only a preference, not requirement; if a voice of the appropriate gender is not available, the synthesizer should substitute a voice with a different gender rather than failing the request.

  • Type

    SsmlVoiceGender

_delattr_(key)

Delete the value on the given field.

This is generally equivalent to setting a falsy value.

_eq_(other)

Return True if the messages are equal, False otherwise.

_ne_(other)

Return True if the messages are unequal, False otherwise.

_setattr_(key, value)

Set the value on the given field.

For well-known protocol buffer types which are marshalled, either the protocol buffer object or the Python equivalent is accepted.