Google Cloud Text to Speech 操作符

先决任务

要使用这些操作符,您必须执行一些操作

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/providers/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/providers/google/cloud/text_to_speech/example_text_to_speech.py[源代码]

FILENAME = "gcp-speech-test-file"

使用运算符

tests/system/providers/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",
)

参考

有关详细信息,请查看

此条目有帮助吗?