Google Cloud Text to Speech 算子¶
前提任务¶
要使用这些算子,您必须完成以下几项工作
使用 Cloud Console 选择或创建一个 Cloud Platform 项目。
为您的项目启用结算功能,详见 Google Cloud 文档。
启用 API,详见 Cloud Console 文档。
通过 pip 安装 API 库。
pip install 'apache-airflow[google]'详细信息请参阅 安装。
CloudTextToSpeechSynthesizeOperator¶
将文本合成音频文件并存储到 Google Cloud Storage
有关参数定义,请参考 CloudTextToSpeechSynthesizeOperator
参数¶
input、voice 和 audio_config 参数需要是 dict 或来自 google.cloud.texttospeech_v1.types
模块中相应类的对象
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",
)
参考¶
更多信息,请参阅