Google Cloud Text to Speech 運算元

前提任務

要使用這些運算元,您必須完成以下幾項工作

CloudTextToSpeechSynthesizeOperator

將文字合成音訊檔案並存儲到 Google Cloud Storage

有關引數定義,請參考 CloudTextToSpeechSynthesizeOperator

引數

input、voice 和 audio_config 引數需要是 dict 或來自 google.cloud.texttospeech_v1.types 模組中相應類的物件

更多資訊請參閱:https://googleapis.github.io/google-cloud-python/latest/texttospeech/gapic/v1/api.html#google.cloud.texttospeech_v1.TextToSpeechClient.synthesize_speech

tests/system/google/cloud/text_to_speech/example_text_to_speech.py

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

filename 引數是一個簡單的字串引數

tests/system/google/cloud/text_to_speech/example_text_to_speech.py

FILENAME = "gcp-speech-test-file"

使用運算元

tests/system/google/cloud/text_to_speech/example_text_to_speech.py

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

模板化

template_fields: Sequence[str] = (
    "input_data",
    "voice",
    "audio_config",
    "project_id",
    "gcp_conn_id",
    "target_bucket_name",
    "target_filename",
    "impersonation_chain",
)

參考

更多資訊,請參閱

此條目是否有幫助?