Google Cloud Text to Speech Operators

Prerequisite Tasks

CloudTextToSpeechSynthesizeOperator

Synthesizes text to audio file and stores it to Google Cloud Storage

For parameter definition, take a look at CloudTextToSpeechSynthesizeOperator

Arguments

The input, voice and audio_config arguments need to be dicts or objects of corresponding classes from google.cloud.texttospeech_v1.types module

for more information, see: https://googleapis.github.io/google-cloud-python/latest/texttospeech/gapic/v1/api.html#google.cloud.texttospeech_v1.TextToSpeechClient.synthesize_speech

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

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

The filename argument is a simple string argument:

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

FILENAME = "gcp-speech-test-file"

Using the operator

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

text_to_speech_synthesize_task = CloudTextToSpeechSynthesizeOperator(
    project_id=GCP_PROJECT_ID,
    input_data=INPUT,
    voice=VOICE,
    audio_config=AUDIO_CONFIG,
    target_bucket_name=BUCKET_NAME,
    target_filename=FILENAME,
    task_id="text_to_speech_synthesize_task",
)
text_to_speech_synthesize_task2 = CloudTextToSpeechSynthesizeOperator(
    input_data=INPUT,
    voice=VOICE,
    audio_config=AUDIO_CONFIG,
    target_bucket_name=BUCKET_NAME,
    target_filename=FILENAME,
    task_id="text_to_speech_synthesize_task2",
)

Templating

template_fields = (
    "input_data",
    "voice",
    "audio_config",
    "project_id",
    "gcp_conn_id",
    "target_bucket_name",
    "target_filename",
    "impersonation_chain",
)

Reference

For further information, look at:

Was this entry helpful?