Specify a regional endpoint

Text-to-Speech offers US and EU regional API endpoints. If you use a regional endpoint, your data in-transit and at-rest will stay within the continental boundaries of Europe or the USA. Specifying an endpoint is important if your data's location must be controlled in order to comply with local regulatory requirements. There is no functional change to the behavior of the API.

When you use a regional endpoint, make sure to include the matching us or eu location in the parent string. See the Synthesize documentation for more information about configuring the synthesize request body.

Protocol

To perform text to speech synthesis using a regional endpoint, run the applicable command in the table below to configure the correct endpoint:

Multi-region Endpoint override
EU $ export CLOUD_TTS_ENDPOINT=https://eu-texttospeech.googleapis.com
US $ export CLOUD_TTS_ENDPOINT=https://us-texttospeech.googleapis.com

If you are using a Neural2 voice, you must use the following endpoint:

Single-region Endpoint override
US Central1 $ export CLOUD_TTS_ENDPOINT=https://us-central1-texttospeech.googleapis.com

The following code sample demonstrates how to send a synthesis request that keeps all data confined to a specified region. You can substitute either the EU or US regional endpoint for the CLOUD_TTS_ENDPOINT variable.


$ curl   -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
         -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-Standard-A',
            'ssmlGender':'FEMALE'
          },
        'audioConfig':{
          'audioEncoding':'MP3'
        }
      }" $CLOUD_TTS_ENDPOINT/v1/text:synthesize > synthesize-text.txt

This example uses an access token for a service account set up for the project using the Google Cloud CLI. For instructions on installing the gcloud CLI, setting up a project with a service account, and obtaining an access token, see the quickstart.

gcloud

The following commands set a regional endpoint:

Multi-region Endpoint override
EU gcloud config set api_endpoint_overrides/texttospeech https://eu-texttospeech.googleapis.com/
US gcloud config set api_endpoint_overrides/texttospeech https://us-texttospeech.googleapis.com/

After you set the regional endpoint, all data will be confined to the specified region when you send subsequent synthesize requests.