Client for Google Cloud Mediatranslation API

class google.cloud.mediatranslation_v1beta1.SpeechTranslationServiceClient(*, credentials: google.auth.credentials.Credentials = None, transport: Union[str, google.cloud.mediatranslation_v1beta1.services.speech_translation_service.transports.base.SpeechTranslationServiceTransport] = None, client_options: <module 'google.api_core.client_options' from '/workspace/python-media-translation/.nox/docfx/lib/python3.9/site-packages/google/api_core/client_options.py'> = None)

Provides translation from/to media types.

Instantiate the speech translation service 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, **SpeechTranslationServiceTransport]) – 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}

streaming_translate_speech(requests: Optional[Iterator[google.cloud.mediatranslation_v1beta1.types.media_translation.StreamingTranslateSpeechRequest]] = None, *, retry: google.api_core.retry.Retry = <_MethodDefault._DEFAULT_VALUE:

Performs bidirectional streaming speech translation: receive results while sending audio. This method is only available via the gRPC API (not REST).

  • Parameters

    • requests (Iterator[~.media_translation.StreamingTranslateSpeechRequest]) – The request object iterator. The top-level message sent by the client for the StreamingTranslateSpeech method. Multiple StreamingTranslateSpeechRequest messages are sent. The first message must contain a streaming_config message and must not contain audio_content data. All subsequent messages must contain audio_content data and must not contain a streaming_config message.

    • 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

    A streaming speech translation response corresponding to a portion of the audio currently processed.

  • Return type

    Iterable[StreamingTranslateSpeechResponse]

class google.cloud.mediatranslation_v1beta1.StreamingTranslateSpeechConfig(mapping=None, *, ignore_unknown_fields=False, **kwargs)

Config used for streaming translation.

audio_config()

Required. The common config for all the following audio contents.

  • Type

    TranslateSpeechConfig

single_utterance()

Optional. If false or omitted, the system performs continuous translation (continuing to wait for and process audio even if the user pauses speaking) until the client closes the input stream (gRPC API) or until the maximum time limit has been reached. May return multiple StreamingTranslateSpeechResults with the is_final flag set to true.

If true, the speech translator will detect a single spoken utterance. When it detects that the user has paused or stopped speaking, it will return an END_OF_SINGLE_UTTERANCE event and cease translation. When the client receives ‘END_OF_SINGLE_UTTERANCE’ event, the client should stop sending the requests. However, clients should keep receiving remaining responses until the stream is terminated. To construct the complete sentence in a streaming way, one should override (if ‘is_final’ of previous response is false), or append (if ‘is_final’ of previous response is true).

_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.mediatranslation_v1beta1.StreamingTranslateSpeechRequest(mapping=None, *, ignore_unknown_fields=False, **kwargs)

The top-level message sent by the client for the StreamingTranslateSpeech method. Multiple StreamingTranslateSpeechRequest messages are sent. The first message must contain a streaming_config message and must not contain audio_content data. All subsequent messages must contain audio_content data and must not contain a streaming_config message.

streaming_config()

Provides information to the recognizer that specifies how to process the request. The first StreamingTranslateSpeechRequest message must contain a streaming_config message.

  • Type

    StreamingTranslateSpeechConfig

audio_content()

The audio data to be translated. Sequential chunks of audio data are sent in sequential StreamingTranslateSpeechRequest messages. The first StreamingTranslateSpeechRequest message must not contain audio_content data and all subsequent StreamingTranslateSpeechRequest messages must contain audio_content data. The audio bytes must be encoded as specified in StreamingTranslateSpeechConfig. Note: as with all bytes fields, protobuffers use a pure binary representation (not 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.mediatranslation_v1beta1.StreamingTranslateSpeechResponse(mapping=None, *, ignore_unknown_fields=False, **kwargs)

A streaming speech translation response corresponding to a portion of the audio currently processed.

error()

Output only. If set, returns a [google.rpc.Status][google.rpc.Status] message that specifies the error for the operation.

  • Type

    Status

result()

Output only. The translation result that is currently being processed (is_final could be true or false).

  • Type

    StreamingTranslateSpeechResult

speech_event_type()

Output only. Indicates the type of speech event.

  • Type

    SpeechEventType

class SpeechEventType(value)

Indicates the type of speech event.

_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.mediatranslation_v1beta1.StreamingTranslateSpeechResult(mapping=None, *, ignore_unknown_fields=False, **kwargs)

A streaming speech translation result corresponding to a portion of the audio that is currently being processed.

text_translation_result()

Text translation result.

  • Type

    TextTranslationResult

recognition_result()

Output only. The debug only recognition result in original language. This field is debug only and will be set to empty string if not available. This is implementation detail and will not be backward compatible. Still need to decide whether to expose this field by default.

class TextTranslationResult(mapping=None, *, ignore_unknown_fields=False, **kwargs)

Text translation result.

translation()

Output only. The translated sentence.

is_final()

Output only. If false, this StreamingTranslateSpeechResult represents an interim result that may change. If true, this is the final time the translation service will return this particular StreamingTranslateSpeechResult, the streaming translator will not return any further hypotheses for this portion of the transcript and corresponding audio.

detected_source_language_code()

Output only. The source language code (BCP-47) detected in the audio. Speech translation result will translate in the most likely language detected including the alternative source languages and main source_language_code.

_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.

_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.mediatranslation_v1beta1.TranslateSpeechConfig(mapping=None, *, ignore_unknown_fields=False, **kwargs)

Provides information to the speech translation that specifies how to process the request.

audio_encoding()

Required. Encoding of audio data. Supported formats:

  • linear16

Uncompressed 16-bit signed little-endian samples (Linear PCM).

source_language_code()

Required. Source language code (BCP-47) of the input audio.

alternative_source_language_codes()

Optional. A list of up to 3 additional language codes (BCP-47), listing possible alternative languages of the supplied audio. If alternative source languages are listed, speech translation result will translate in the most likely language detected including the main source_language_code. The translated result will include the language code of the language detected in the audio.

  • Type

    Sequence[str]

target_language_code()

Required. Target language code (BCP-47) of the output.

sample_rate_hertz()

Optional. Sample rate in Hertz of the audio data. Valid values are: 8000-48000. 16000 is optimal. For best results, set the sampling rate of the audio source to 16000 Hz. If that’s not possible, use the native sample rate of the audio source (instead of re-sampling). This field can only be omitted for FLAC and WAV audio files.

model()

Optional.

_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.