Google Cloud Speech Translate Operators

Prerequisite Tasks

To use these operators, you must do a few things:

CloudTranslateSpeechOperator

Recognizes speech in audio input and translates it.

For parameter definition, take a look at CloudTranslateSpeechOperator

Arguments

Config and audio arguments need to be dicts or objects of corresponding classes from google.cloud.speech_v1.types module.

for more information, see: https://googleapis.github.io/google-cloud-python/latest/speech/gapic/v1/api.html#google.cloud.speech_v1.SpeechClient.recognize

Arguments for translation need to be specified.

tests/system/providers/google/cloud/translate_speech/example_translate_speech.py[source]

CONFIG = {"encoding": "LINEAR16", "language_code": "en_US"}
AUDIO = {"uri": f"gs://{BUCKET_NAME}/{FILE_NAME}"}
TARGET_LANGUAGE = "pl"
FORMAT = "text"
MODEL = "base"
SOURCE_LANGUAGE = None

Using the operator

tests/system/providers/google/cloud/translate_speech/example_translate_speech.py[source]

translate_speech_task = CloudTranslateSpeechOperator(
    project_id=PROJECT_ID,
    audio=AUDIO,
    config=CONFIG,
    target_language=TARGET_LANGUAGE,
    format_=FORMAT,
    source_language=SOURCE_LANGUAGE,
    model=MODEL,
    task_id="translate_speech_task",
)
translate_speech_task2 = CloudTranslateSpeechOperator(
    audio=AUDIO,
    config=CONFIG,
    target_language=TARGET_LANGUAGE,
    format_=FORMAT,
    source_language=SOURCE_LANGUAGE,
    model=MODEL,
    task_id="translate_speech_task2",
)

Templating

template_fields: Sequence[str] = (
    "target_language",
    "format_",
    "source_language",
    "model",
    "project_id",
    "gcp_conn_id",
    "impersonation_chain",
)
operator_extra_links = (FileDetailsLink(),)

Was this entry helpful?