指定区域端点
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
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 语音:
单区域 |
端点替换 |
US Central1 |
$ 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 端点的请求。如需了解详情,请参阅限制端点使用。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-11。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-11。"],[],[],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)."]]