Organízate con las colecciones
Guarda y clasifica el contenido según tus preferencias.
Transcribir voz a texto con la API
En esta página se explica cómo enviar una solicitud de reconocimiento de voz a Speech-to-Text mediante la interfaz REST y el comando curl.
Speech-to-Text permite integrar de forma sencilla las tecnologías de reconocimiento de voz de Google en las aplicaciones de desarrolladores. Puedes enviar datos de audio a la API Speech-to-Text, que devuelve una transcripción de texto de ese archivo de audio. Para obtener más información sobre el servicio, consulta el artículo Conceptos básicos de Speech-to-Text.
Antes de empezar
Antes de enviar una solicitud a la API Speech-to-Text, debes haber completado las siguientes acciones. Consulta la página Antes de empezar para obtener más información.
Habilita Speech-to-Text en un proyecto de GCP.
Asegúrate de que la facturación esté habilitada en Speech-to-Text.
Instala Google Cloud CLI.
Después de la instalación,
inicializa la CLI de Google Cloud ejecutando el siguiente comando:
(Opcional) Crea un segmento de Google Cloud Storage para almacenar tus datos de audio.
Hacer una solicitud de transcripción de audio
Ahora puedes usar Speech-to-Text para transcribir un archivo de audio a texto. Usa el siguiente código de ejemplo para enviar una solicitud REST recognize a la API Speech-to-Text.
Crea un archivo de solicitud JSON con el siguiente texto y guárdalo como archivo de texto sin formato sync-request.json:
Este fragmento de código JSON indica que el archivo de audio tiene un formato de codificación FLAC, una frecuencia de muestreo de 16.000 Hz y que el archivo de audio está almacenado en Google Cloud Storage en el URI indicado. El archivo de audio es de acceso público, por lo que no necesitas credenciales de autenticación para acceder a él.
Usa curl para hacer una solicitud speech:recognize
y pásale el nombre del archivo de la solicitud JSON que configuraste en el paso 1:
El comando curl de ejemplo usa el comando gcloud auth print-access-token para obtener un token de autenticación.
Ten en cuenta que, para pasar un nombre de archivo a curl, debes usar la opción -d (para "datos") y preceder el nombre de archivo con el signo @. Este archivo debe estar en el mismo directorio en el que ejecutes el comando curl.
Deberías ver una respuesta similar a la siguiente:
{"results":[{"alternatives":[{"transcript":"how old is the Brooklyn Bridge","confidence":0.98267895}]}]}
¡Enhorabuena! Has enviado tu primera solicitud a Speech-to-Text.
[[["Es fácil de entender","easyToUnderstand","thumb-up"],["Me ofreció una solución al problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Es difícil de entender","hardToUnderstand","thumb-down"],["La información o el código de muestra no son correctos","incorrectInformationOrSampleCode","thumb-down"],["Me faltan las muestras o la información que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-08-20 (UTC)."],[],[],null,["# Quickstart: Transcribe speech to text by using the API\n\nTranscribe speech to text by using the API\n==========================================\n\nThis page shows you how to send a speech recognition request to\nSpeech-to-Text using the [REST interface](/speech-to-text/docs/reference/rest)\nand the `curl` command.\n\n\nSpeech-to-Text enables easy integration of Google speech\nrecognition technologies into developer applications. You can send\naudio data to the Speech-to-Text API, which then returns a\ntext transcription of that audio file. For more information about\nthe service, see\n[Speech-to-Text basics](/speech-to-text/docs/basics).\n\n\nBefore you begin\n----------------\n\nBefore you can send a request to the Speech-to-Text API, you must have completed\nthe following actions. See the\n[before you begin](/speech-to-text/docs/before-you-begin) page for details.\n\n- Enable Speech-to-Text on a GCP project.\n 1. Make sure billing is enabled for Speech-to-Text.\n-\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n- (Optional) Create a new Google Cloud Storage bucket to store your audio data.\n\nMake an audio transcription request\n-----------------------------------\n\nNow you can use Speech-to-Text to transcribe an audio file\nto text. Use the following code sample to send a\n[`recognize`](/speech-to-text/docs/reference/rest/v1/speech/recognize) REST request to the Speech-to-Text API.\n\n1. Create a JSON request file with the following text, and save it as a\n `sync-request.json` plain text file:\n\n ```json\n {\n \"config\": {\n \"encoding\":\"FLAC\",\n \"sampleRateHertz\": 16000,\n \"languageCode\": \"en-US\",\n \"enableWordTimeOffsets\": false\n },\n \"audio\": {\n \"uri\":\"gs://cloud-samples-tests/speech/brooklyn.flac\"\n }\n }\n \n ```\n\n This JSON snippet indicates that the audio file has a FLAC encoding format,\n a sample rate of 16000 Hz, and that the audio file is stored on Google Cloud\n Storage at the given URI. The audio file is publicly accessible, so you\n don't need authentication credentials to access the file.\n2. Use `curl` to make a `speech:recognize`\n request, passing it the filename of the JSON request you set up in step 1:\n\n The sample `curl` command uses the `gcloud auth print-access-token` command to get an authentication token. \n\n ```sh\n curl -s -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer \"$(gcloud auth print-access-token) \\\n https://speech.googleapis.com/v1/speech:recognize \\\n -d @sync-request.json\n \n ```\n\n Note that to pass a filename to `curl` you use the\n `-d` option (for \"data\") and precede the filename with an\n `@` sign. This file should be in the same directory in which you\n execute the `curl` command.\n\n You should see a response similar to the following: \n\n ```json\n {\n \"results\": [\n {\n \"alternatives\": [\n {\n \"transcript\": \"how old is the Brooklyn Bridge\",\n \"confidence\": 0.98267895\n }\n ]\n }\n ]\n }\n \n ```\n\nCongratulations! You've sent your first request to Speech-to-Text.\n\n\nIf you receive an error or an empty response from\nSpeech-to-Text, take a look at the\n[troubleshooting](/speech-to-text/docs/troubleshooting) and\n[error mitigation](/speech-to-text/docs/error-messages) steps.\n\nClean up\n--------\n\n\nTo avoid incurring charges to your Google Cloud account for\nthe resources used on this page, follow these steps.\n\n- Use the [Google Cloud console](https://console.cloud.google.com/) to delete your project if you do not need it.\n\nWhat's next\n-----------\n\n\n- Practice [transcribing short audio files](/speech-to-text/docs/sync-recognize).\n- Learn how to [batch long audio files for speech recognition](/speech-to-text/docs/async-recognize).\n- Learn how to [transcribe streaming audio](/speech-to-text/docs/streaming-recognize) like from a microphone.\n- Get started with the Speech-to-Text in your language of choice by using a [Speech-to-Text client library](/speech-to-text/docs/reference/libraries).\n- Work through the [sample applications](/speech-to-text/docs/samples).\n- For best performance, accuracy, and other tips, see the [best practices](/speech-to-text/docs/best-practices) documentation.\n\n\u003cbr /\u003e"]]