Google Cloud Speech Translate 操作符

先决条件任务

要使用这些操作符,您必须执行以下几项操作

CloudTranslateSpeechOperator

识别音频输入中的语音并将其翻译。

有关参数定义,请参阅CloudTranslateSpeechOperator

参数

配置和音频参数需要是 google.cloud.speech_v1.types 模块中相应类的字典或对象。

有关更多信息,请参阅:https://googleapis.github.io/google-cloud-python/latest/speech/gapic/v1/api.html#google.cloud.speech_v1.SpeechClient.recognize

需要指定翻译参数。

tests/system/providers/google/cloud/translate_speech/example_translate_speech.py[源代码]

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

使用运算符

tests/system/providers/google/cloud/translate_speech/example_translate_speech.py[源代码]

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",
)

模板化

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

此条目有帮助吗?