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

tests/system/providers/google/cloud/speech_to_text/example_speech_to_text.py[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:

tests/system/providers/google/cloud/speech_to_text/example_speech_to_text.py[source]

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

Using the operator

tests/system/providers/google/cloud/speech_to_text/example_speech_to_text.py[source]

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

Templating

template_fields: Sequence[str] = (
    "audio",
    "config",
    "project_id",
    "gcp_conn_id",
    "timeout",
    "impersonation_chain",
)

Reference

For further information, look at:

Was this entry helpful?