Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
A Speech-to-Text oferece endpoints de API regionais dos EUA e da UE.
Se você usar um endpoint regional, os dados em repouso e em uso vão permanecer
dentro dos limites continentais da Europa ou dos EUA. Especificar um endpoint
é importante quando o local dos dados precisa ser controlado para cumprir
os requisitos regulamentares locais. Não há alteração funcional no comportamento
da API.
Usar endpoints regionais
Ao usar um endpoint regional, inclua o local us ou eu
correspondente na string parent. Consulte a
documentação
RecognitionConfig para saber como configurar o corpo da solicitação
de reconhecimento.
Protocolo
Para realizar o reconhecimento de fala usando um endpoint regional, execute o
comando aplicável na tabela abaixo para configurar o endpoint correto:
O exemplo de código a seguir demonstra como enviar um
recognize request
que mantém todos os dados restritos a uma região específica. É possível substituir o endpoint
regional EU ou US pela
variável CLOUD_SPEECH_ENDPOINT.
Esse exemplo usa a CLI do Google Cloud para gerar
credenciais para a conta de usuário. Para saber como instalar e inicializar a
gcloud CLI, consulte o
guia de início rápido.
O conteúdo de áudio fornecido no corpo da solicitação está codificado em Base64.
Para saber como codificar áudios em Base64, consulte
Como codificar conteúdos de áudio em Base64. Para saber mais sobre o
campo content, consulte
RecognitionAudio.
gcloud
Os comandos abaixo definem um endpoint regional:
Multirregional
Substituição do endpoint
UE
gcloud config set api_endpoint_overrides/speech https://eu-speech.googleapis.com/
EUA
gcloud config set api_endpoint_overrides/speech https://us-speech.googleapis.com/
Depois que você definir o endpoint regional, todos os dados serão limitados à região especificada
quando você enviar o recognize requests.
O exemplo a seguir demonstra uma solicitação de reconhecimento.
# Imports the Google Cloud client libraryfromgoogle.api_coreimportclient_optionsfromgoogle.cloudimportspeechdefsync_recognize_with_multi_region_gcs()-> speech.RecognizeResponse:"""Recognizes speech synchronously in the GCS bucket."""# Instantiates a client# Pass an additional argument, ClientOptions, to specify the new endpoint._client_options=client_options.ClientOptions(api_endpoint="eu-speech.googleapis.com")client=speech.SpeechClient(client_options=_client_options)# The name of the audio file to transcribegcs_uri="gs://cloud-samples-data/speech/brooklyn_bridge.raw"audio=speech.RecognitionAudio(uri=gcs_uri)config=speech.RecognitionConfig(encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,sample_rate_hertz=16000,language_code="en-US",)# Detects speech in the audio fileresponse=client.recognize(config=config,audio=audio)forresultinresponse.results:print(f"Transcript: {result.alternatives[0].transcript}")returnresponse.results
Restringir o uso de endpoints de API globais
Para ajudar na aplicação do uso de endpoints regionais, utilize a
restrição de política da organização constraints/gcp.restrictEndpointUsage para
bloquear solicitações ao endpoint da API global. Para mais informações, consulte
Restringir o uso de endpoints.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-02 UTC."],[],[],null,["# Specify a regional endpoint\n\nSpeech-to-Text 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[`RecognitionConfig`](/speech-to-text/docs/reference/rest/v1/RecognitionConfig)\ndocumentation for more information about configuring the recognition request\nbody. \n\n### Protocol\n\nTo perform speech recognition using a regional endpoint, run the\napplicable command in the table below to configure the correct endpoint:\n\nThe following code sample demonstrates how to send a\n[`recognize request`](/sdk/gcloud/reference/ml/speech/recognize)\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_SPEECH_ENDPOINT\u003c/var\u003e\nvariable. \n\n```bash\n$ curl -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer \"$(gcloud auth print-access-token) \\\n $\u003cvar translate=\"no\"\u003eCLOUD_SPEECH_ENDPOINT\u003c/var\u003e/v1/speech:recognize \\\n --data \"{\n 'config': {\n 'encoding': 'LINEAR16',\n 'languageCode': 'en-US'\n },\n 'audio': {\n 'uri':'gs://speech-samples-00/commercial_mono.wav'\n }\n }\"\n```\n\nThis example uses [Google Cloud CLI](/sdk/docs/install) to generate\ncredentials for your user account. To learn how to install and initialize the\ngcloud CLI, see the\n[quickstart](/speech-to-text/docs/transcribe-api).\n\nThe audio content supplied in the request body is base64-encoded.\nFor more information on how to base64-encode audio, see\n[Base64 Encoding Audio Content](/speech-to-text/docs/base64-encoding). For more information on the\n`content` field, see\n[RecognitionAudio](/speech-to-text/docs/reference/rest/v1/RecognitionAudio).\n\n### gcloud\n\nThe following commands set a regional endpoint:\n\nAfter you set the regional endpoint, all data will be confined to the specified\nregion when you send subsequent [`recognize requests`](/sdk/gcloud/reference/ml/speech/recognize).\nThe following example demonstrates a recognize request. \n\n```bash\n$ gcloud ml speech recognize gs://cloud-samples-tests/speech/brooklyn.flac \\\n --language-code=en-US --log-http\n```\n\n### Python\n\n\nTo learn how to install and use the client library for Speech-to-Text, see\n[Speech-to-Text client libraries](/speech-to-text/docs/client-libraries).\n\n\nFor more information, see the\n[Speech-to-Text Python API\nreference documentation](/python/docs/reference/speech/latest).\n\n\nTo authenticate to Speech-to-Text, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n # Imports the Google Cloud client library\n from google.api_core import client_options\n from google.cloud import speech\n\n\n def sync_recognize_with_multi_region_gcs() -\u003e speech.RecognizeResponse:\n \"\"\"Recognizes speech synchronously in the GCS bucket.\"\"\"\n\n # Instantiates a client\n\n # Pass an additional argument, ClientOptions, to specify the new endpoint.\n _client_options = client_options.ClientOptions(\n api_endpoint=\"eu-speech.googleapis.com\"\n )\n\n client = speech.SpeechClient(client_options=_client_options)\n\n # The name of the audio file to transcribe\n gcs_uri = \"gs://cloud-samples-data/speech/brooklyn_bridge.raw\"\n\n audio = speech.RecognitionAudio(uri=gcs_uri)\n\n config = speech.RecognitionConfig(\n encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,\n sample_rate_hertz=16000,\n language_code=\"en-US\",\n )\n\n # Detects speech in the audio file\n response = client.recognize(config=config, audio=audio)\n\n for result in response.results:\n print(f\"Transcript: {result.alternatives[0].transcript}\")\n\n return response.results\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)."]]