Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Speech-to-Text menawarkan endpoint API regional AS dan Uni Eropa.
Jika Anda menggunakan endpoint regional, data dalam penyimpanan dan yang sedang digunakan akan tetap berada dalam batas benua Eropa atau AS. Menentukan endpoint
penting jika lokasi data Anda harus dikontrol untuk mematuhi
persyaratan peraturan setempat. Tidak ada perubahan fungsional pada perilaku API.
Menggunakan endpoint regional
Saat Anda menggunakan endpoint regional, pastikan untuk menyertakan lokasi us atau eu
yang cocok dalam string parent. Lihat dokumentasi RecognitionConfig untuk mengetahui informasi selengkapnya tentang cara mengonfigurasi isi permintaan pengenalan.
Protocol
Untuk melakukan pengenalan ucapan menggunakan endpoint regional, jalankan perintah yang berlaku pada tabel di bawah untuk mengonfigurasi endpoint yang benar:
Contoh kode berikut menunjukkan cara mengirim
recognize request
yang menyimpan semua data hanya untuk region yang ditentukan. Anda dapat mengganti endpoint regional EU atau US untuk variabel CLOUD_SPEECH_ENDPOINT.
Contoh ini menggunakan Google Cloud CLI untuk membuat
kredensial untuk akun pengguna Anda. Untuk mempelajari cara menginstal dan melakukan inisialisasi
gcloud CLI, lihat
panduan memulai.
Konten audio yang disediakan dalam isi permintaan berenkode base64.
Untuk informasi selengkapnya tentang cara mengenkode audio dengan base64, lihat
Mengenkode Konten Audio Base64. Untuk mengetahui informasi selengkapnya tentang
kolom content, lihat
RecognitionAudio.
gcloud
Perintah berikut menetapkan endpoint regional:
Multi-region
Penggantian endpoint
Uni Eropa - EU
gcloud config set api_endpoint_overrides/speech https://eu-speech.googleapis.com/
AS
gcloud config set api_endpoint_overrides/speech https://us-speech.googleapis.com/
Setelah Anda menetapkan endpoint regional, semua data akan dibatasi ke region yang ditentukan
saat Anda mengirim recognize requests berikutnya.
Contoh berikut menunjukkan permintaan pengenalan.
# 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
Membatasi penggunaan endpoint API global
Untuk membantu menerapkan penggunaan endpoint regional, gunakan batasan kebijakan organisasi constraints/gcp.restrictEndpointUsage untuk memblokir permintaan ke endpoint API global. Untuk mengetahui informasi selengkapnya, lihat
Membatasi penggunaan endpoint.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]