airflow.providers.google.cloud.operators.translate_speech¶
此模块包含一个 Google Cloud 语音翻译 Operator。
类¶
识别音频输入中的语音并进行翻译。 |
模块内容¶
- class airflow.providers.google.cloud.operators.translate_speech.CloudTranslateSpeechOperator(*, audio, config, target_language, format_, source_language, model, project_id=PROVIDE_PROJECT_ID, gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]¶
基类:
airflow.providers.google.cloud.operators.cloud_base.GoogleCloudBaseOperator
识别音频输入中的语音并进行翻译。
请注意,它使用识别 API 响应中的第一个结果 - 即置信度最高的结果。为了查看其他可能的结果,请分别使用 CloudSpeechToTextRecognizeSpeechOperator 和 CloudTranslateTextOperator
另请参阅
有关如何使用此 Operator 的更多信息,请参阅指南: CloudTranslateSpeechOperator
请参阅 https://cloud.google.com/translate/docs/translating-text
执行方法返回包含翻译结果的字符串对象
这是一个字典列表(查询到的值)。字典通常包含三个键(尽管并非所有情况都会全部出现)。
detectedSourceLanguage
: 检测到的文本语言(ISO 639-1 语言代码)。translatedText
: 文本翻译为目标语言的结果。input
: 对应的输入值。model
: 用于翻译文本的模型。
字典将作为 XCom 返回值设置。
- 参数:
audio (google.cloud.speech_v1.types.RecognitionAudio) – 要识别的音频数据。详见: https://googleapis.github.io/google-cloud-python/latest/speech/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionAudio
config (google.cloud.speech_v1.types.RecognitionConfig) – 提供给识别器的信息,指定如何处理请求。详见: https://googleapis.github.io/google-cloud-python/latest/speech/gapic/v1/types.html#google.cloud.speech_v1.types.RecognitionConfig
target_language (str) – 将结果翻译成的语言。这是 API 所必需的,默认为当前实例的目标语言。在此查看可用语言列表: https://cloud.google.com/translate/docs/languages
format – (可选) `text` 或 `html` 中的一种,用于指定输入文本是纯文本还是 HTML。
source_language (str | None) – (可选) 要翻译的文本的语言。
model (str) – (可选) 用于翻译文本的模型,例如
'base'
或'nmt'
。project_id (str) – 可选,Compute Engine 实例所在的 Google Cloud 项目 ID。如果设置为 None 或缺失,则使用 Google Cloud 连接中的默认 project_id。
gcp_conn_id (str) – 可选,用于连接 Google Cloud 的连接 ID。默认为 ‘google_cloud_default’。
impersonation_chain (str | collections.abc.Sequence[str] | None) – 可选的服务帐号,用于使用短期凭据进行模拟,或者需要获取列表中最后一个帐号的 access_token 的帐号链列表,该帐号将在请求中被模拟。如果设置为字符串,则此帐号必须授予发起帐号 Service Account Token Creator IAM 角色。如果设置为序列,则列表中的身份必须授予紧接在其前的身份 Service Account Token Creator IAM 角色,列表中的第一个帐号将此角色授予发起帐号(模板化)。
- template_fields: collections.abc.Sequence[str] = ('target_language', 'format_', 'source_language', 'model', 'project_id', 'gcp_conn_id',...[source]¶