Google Cloud 文字轉語音運算子¶
先決條件任務¶
若要使用這些運算子,您必須執行以下幾項操作
使用 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
引數需要是字典或來自 google.cloud.texttospeech_v1.types
模組的對應類別的物件
INPUT = {"text": "Sample text for demo purposes"}
VOICE = {"language_code": "en-US", "ssml_gender": "FEMALE"}
AUDIO_CONFIG = {"audio_encoding": "LINEAR16"}
filename
引數是一個簡單的字串引數
FILENAME = "gcp-speech-test-file"
使用運算子¶
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",
)