Speech-to-Text offers US and EU regional API endpoints. If you use a regional endpoint, your data at-rest and in-use 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
RecognitionConfig
documentation for more information about configuring the recognition request
body.
Protocol
To perform speech recognition using a regional endpoint, run the applicable command in the table below to configure the correct endpoint:
Multi-region | Endpoint override |
---|---|
EU | $ export CLOUD_SPEECH_ENDPOINT=https://eu-speech.googleapis.com |
US | $ export CLOUD_SPEECH_ENDPOINT=https://us-speech.googleapis.com |
The following code sample demonstrates how to send a
recognize request
that keeps all data confined to a specified region. You can substitute either
the EU
or US
regional endpoint for the CLOUD_SPEECH_ENDPOINT
variable.
$ curl -H "Content-Type: application/json" \ -H "Authorization: Bearer "$(gcloud auth print-access-token) \ $CLOUD_SPEECH_ENDPOINT/v1/speech:recognize \ --data "{ 'config': { 'encoding': 'LINEAR16', 'languageCode': 'en-US' }, 'audio': { 'uri':'gs://speech-samples-00/commercial_mono.wav' } }"
This example uses Google Cloud CLI to generate credentials for your user account. To learn how to install and initialize the gcloud CLI, see the quickstart.
The audio content supplied in the request body is base64-encoded.
For more information on how to base64-encode audio, see
Base64 Encoding Audio Content. For more information on the
content
field, see
RecognitionAudio.
gcloud
The following commands set a regional endpoint:
Multi-region | Endpoint override |
---|---|
EU | gcloud config set api_endpoint_overrides/speech https://eu-speech.googleapis.com/ |
US | gcloud config set api_endpoint_overrides/speech https://us-speech.googleapis.com/ |
After you set the regional endpoint, all data will be confined to the specified
region when you send subsequent recognize requests
.
The following example demonstrates a recognize request.
$ gcloud ml speech recognize gs://cloud-samples-tests/speech/brooklyn.flac \ --language-code=en-US --log-http
Python
To learn how to install and use the client library for Speech-to-Text, see Speech-to-Text client libraries. For more information, see the Speech-to-Text Python API reference documentation.
To authenticate to Speech-to-Text, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.