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",
)
參考¶
更多資訊,請參閱