Google Cloud Speech to Text Operators

Prerequisite Tasks

CloudSpeechToTextRecognizeSpeechOperator

Recognizes speech in audio input and returns text.

For parameter definition, take a look at CloudSpeechToTextRecognizeSpeechOperator

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/providers/google/cloud/example_dags/example_speech_to_text.pyView Source

INPUT = {"text": "Sample text for demo purposes"}
VOICE = {"language_code": "en-US", "ssml_gender": "FEMALE"}
AUDIO_CONFIG = {"audio_encoding": "LINEAR16"}

filename is a simple string argument:

airflow/providers/google/cloud/example_dags/example_speech_to_text.pyView Source

CONFIG = {"encoding": "LINEAR16", "language_code": "en_US"}
AUDIO = {"uri": f"gs://{BUCKET_NAME}/{FILENAME}"}

Using the operator

airflow/providers/google/cloud/example_dags/example_speech_to_text.pyView Source

speech_to_text_recognize_task2 = CloudSpeechToTextRecognizeSpeechOperator(
    config=CONFIG, audio=AUDIO, task_id="speech_to_text_recognize_task"
)

Templating

template_fields = (
    "audio",
    "config",
    "project_id",
    "gcp_conn_id",
    "timeout",
    "impersonation_chain",
)

Reference

For further information, look at:

Was this entry helpful?