Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Speech-to-Text offre endpoint API regionali per Stati Uniti e UE.
Se utilizzi un endpoint regionale, i dati non attivi e in uso rimarranno
entro i confini continentali dell'Europa o degli Stati Uniti. La specifica di un endpoint
è importante se la posizione dei dati deve essere controllata per rispettare
i requisiti normativi locali. Non sono state apportate modifiche funzionali al comportamento
dell'API.
Utilizzare endpoint regionali
Quando utilizzi un endpoint regionale, assicurati di includere la località us o eu
corrispondente nella stringa parent. Per ulteriori informazioni sulla configurazione del corpo della richiesta di riconoscimento, consulta la documentazione relativa a
RecognitionConfig.
Protocollo
Per eseguire il riconoscimento vocale utilizzando un endpoint regionale, esegui il comando
applicabile nella tabella seguente per configurare l'endpoint corretto:
Il seguente esempio di codice mostra come inviare un
recognize request
che mantiene tutti i dati confinati in una regione specificata. Puoi sostituire l'endpoint regionale EU o US con la variabile CLOUD_SPEECH_ENDPOINT.
Questo esempio utilizza Google Cloud CLI per generare
le credenziali per il tuo account utente. Per scoprire come installare e inizializzare
gcloud CLI, consulta la
guida rapida.
I contenuti audio forniti nel corpo della richiesta sono codificati in base64.
Per ulteriori informazioni su come codificare l'audio in base64, consulta
Codifica in base64 dei contenuti audio. Per ulteriori informazioni sul campo
content, vedi
RecognitionAudio.
gcloud
I seguenti comandi impostano un endpoint regionale:
Più regioni
Override dell'endpoint
UE
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/
Dopo aver impostato l'endpoint regionale, tutti i dati verranno limitati alla regione specificata quando invii recognize requests successivi.
L'esempio seguente mostra una richiesta di riconoscimento.
# 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
Limita l'utilizzo degli endpoint API globali
Per contribuire a imporre l'utilizzo di endpoint regionali, utilizza il vincolo del criterio dell'organizzazione constraints/gcp.restrictEndpointUsage per bloccare le richieste all'endpoint API globale. Per ulteriori informazioni, vedi
Limitare l'utilizzo degli endpoint.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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)."]]