Google Cloud Speech Translate Operators

GcpTranslateSpeechOperator

Recognizes speech in audio input and translates it.

For parameter definition, take a look at airflow.contrib.operators.gcp_translate_speech_operator.GcpTranslateSpeechOperator

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

airflow/contrib/example_dags/example_gcp_speech.pyView Source

CONFIG = {"encoding": "LINEAR16", "language_code": "en_US"}
AUDIO = {"uri": "gs://{bucket}/{object}".format(bucket=BUCKET_NAME, object=FILENAME)}

Arguments for translation need to be specified.

airflow/contrib/example_dags/example_gcp_speech.pyView Source

TARGET_LANGUAGE = 'pl'
FORMAT = 'text'
MODEL = 'base'
SOURCE_LANGUAGE = None

Using the operator

airflow/contrib/example_dags/example_gcp_speech.pyView Source

translate_speech_task = GcpTranslateSpeechOperator(
    project_id=GCP_PROJECT_ID,
    audio=AUDIO,
    config=CONFIG,
    target_language=TARGET_LANGUAGE,
    format_=FORMAT,
    source_language=SOURCE_LANGUAGE,
    model=MODEL,
    task_id='translate_speech_task'
)

Templating

template_fields = ('target_language', 'format_', 'source_language', 'model', 'project_id', 'gcp_conn_id')

Was this entry helpful?