指定區域端點
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
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」。
限制全球 API 端點用量
如要強制使用區域端點,請使用constraints/gcp.restrictEndpointUsage
機構政策限制,封鎖對全域 API 端點的要求。詳情請參閱「限制端點用量」一文。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-04 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Specify a regional endpoint\n\nText-to-Speech offers US and EU regional API endpoints.\nIf you use a regional endpoint, your data at-rest and in-use will stay\nwithin the continental boundaries of Europe or the USA. Specifying an endpoint\nis important if your data's location must be controlled in order to comply with\nlocal regulatory requirements. There is no functional change to the behavior of\nthe API.\n\nUse regional endpoints\n----------------------\n\nWhen you use a regional endpoint, make sure to include the matching `us` or `eu`\nlocation in the `parent` string. See the\n[`Synthesize`](/text-to-speech/docs/create-audio)\ndocumentation for more information about configuring the synthesize request\nbody. \n\n### Protocol\n\nTo perform text to speech synthesis using a regional endpoint, run the\napplicable command in the table below to configure the correct endpoint:\n\nOnly Neural2 voices are available from these endpoints:\n\nThe following code sample demonstrates how to send a\n[`synthesis request`](/text-to-speech/docs/reference/rest/v1beta1/text/synthesize)\nthat keeps all data confined to a specified region. You can substitute either\nthe `EU` or `US` regional endpoint for the \u003cvar translate=\"no\"\u003eCLOUD_TTS_ENDPOINT\u003c/var\u003e\nvariable. Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your project ID. \n\n```bash\n$ curl -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"x-goog-user-project: \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\" \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n --data \"{\n 'input':{\n 'text':'Android is a mobile operating system developed by Google,\n based on the Linux kernel and designed primarily for\n touchscreen mobile devices such as smartphones and tablets.'\n },\n 'voice':{\n 'languageCode':'en-gb',\n 'name':'en-GB-Neural2-A',\n 'ssmlGender':'FEMALE'\n },\n 'audioConfig':{\n 'audioEncoding':'MP3'\n }\n }\" $\u003cvar translate=\"no\"\u003eCLOUD_TTS_ENDPOINT\u003c/var\u003e/v1/text:synthesize \u003e synthesize-text.txt\n```\n\nThis example uses the [Google Cloud CLI](/sdk/docs/install) to create an access\ntoken for your Google Account. For instructions on installing the\ngcloud CLI, see\n[Authenticate to Text-to-Speech](/text-to-speech/docs/authentication).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nRestrict global API endpoint usage\n----------------------------------\n\nTo help enforce the use of regional endpoints, use the\n`constraints/gcp.restrictEndpointUsage` organization policy constraint to block\nrequests to the global API endpoint. For more information, see\n[Restricting endpoint usage](/assured-workloads/docs/restrict-endpoint-usage)."]]