Text-to-Speech 提供美國和歐盟區域 API 端點。 如果您使用區域端點,靜態和使用中的資料會保留在歐洲或美國的大陸邊界內。如果必須控管資料位置,才能遵守當地法規要求,請務必指定端點。API 行為沒有任何功能變更。
使用地區端點時,請務必在 parent
字串中加入相符的 us
或 eu
位置。如要進一步瞭解如何設定合成要求主體,請參閱 Synthesize
說明文件。
通訊協定
如要使用區域端點執行文字轉語音合成,請在下表中執行適用的指令,設定正確的端點:
多區域 | 端點覆寫 |
---|---|
歐盟 | $ export CLOUD_TTS_ENDPOINT=https://eu-texttospeech.googleapis.com |
美國 | $ export CLOUD_TTS_ENDPOINT=https://us-texttospeech.googleapis.com |
下列端點僅提供 Neural2 聲音:
單一區域 | 端點覆寫 |
---|---|
美國中部 1 | $ export CLOUD_TTS_ENDPOINT=https://us-central1-texttospeech.googleapis.com |
以下程式碼範例說明如何傳送 synthesis request
,將所有資料限制在特定區域。您可以將 EU
或 US
區域端點替換為 CLOUD_TTS_ENDPOINT 變數。將 PROJECT_ID 替換為您的專案 ID。
$ curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "x-goog-user-project: PROJECT_ID" \ -H "Content-Type: application/json; charset=utf-8" \ --data "{ 'input':{ 'text':'Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets.' }, 'voice':{ 'languageCode':'en-gb', 'name':'en-GB-Neural2-A', 'ssmlGender':'FEMALE' }, 'audioConfig':{ 'audioEncoding':'MP3' } }" $CLOUD_TTS_ENDPOINT/v1/text:synthesize > synthesize-text.txt
這個範例使用 Google Cloud CLI 為 Google 帳戶建立存取權杖。如需安裝 gcloud CLI 的操作說明,請參閱「驗證 Text-to-Speech」。