Google Cloud 文字轉語音運算子

先決條件任務

若要使用這些運算子,您必須執行以下幾項操作

CloudTextToSpeechSynthesizeOperator

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

如需參數定義,請參閱 CloudTextToSpeechSynthesizeOperator

引數

inputvoiceaudio_config 引數需要是字典或來自 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",
)

參考

如需更多資訊,請查看

此條目是否有幫助?