Google Cloud Speech Translate Operators¶
Prerequisite Tasks¶
To use these operators, you must do a few things:
Select or create a Cloud Platform project using the Cloud Console.
Enable billing for your project, as described in the Google Cloud documentation.
Enable the API, as described in the Cloud Console documentation.
Install API libraries via pip.
pip install 'apache-airflow[google]'Detailed information is available for Installation.
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.
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
Using the operator¶
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(),)