Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Transcrire la voix en texte à l'aide de gcloud CLI
Cette page explique comment envoyer une requête de reconnaissance vocale à Speech-to-Text avec l'outil gcloud depuis la ligne de commande.
Speech-to-Text permet d'intégrer facilement les technologies de reconnaissance vocale Google aux applications en cours de développement. Vous pouvez envoyer des données audio à l'API Speech-to-Text, qui renvoie ensuite une transcription de ce fichier audio en texte. Pour plus d'informations sur le service, consultez la page Principes de base de Speech-to-Text.
Avant de commencer
Avant de pouvoir envoyer une requête à l'API Speech-to-Text, vous devez avoir effectué les actions suivantes. Pour en savoir plus, consultez la page Avant de commencer.
Activez Speech-to-Text sur un projet GCP.
Assurez-vous que la facturation est activée pour Speech-to-Text.
Install the Google Cloud CLI.
After installation,
initialize the Google Cloud CLI by running the following command:
(Facultatif) Créez un bucket Google Cloud Storage pour stocker vos données audio.
Envoyer une requête de transcription audio
Speech-to-Text vous permet désormais de transcrire un fichier audio en texte. Servez-vous de l'exemple de code suivant pour envoyer une requête recognize à l'API Speech-to-Text.
Ouvrez l'interface système de ligne de commande, puis exécutez la commande suivante :
Pour obtenir des conseils, entre autres sur l'optimisation des performances et l'amélioration de la précision, consultez la documentation relative aux bonnes pratiques.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[],[],null,["# Quickstart: Transcribe speech to text by using the gcloud CLI\n\nTranscribe speech to text by using the gcloud CLI\n=================================================\n\nThis page shows you how to send a speech recognition request to\nSpeech-to-Text using the\n[`gcloud`](/sdk/gcloud/reference/ml/speech) tool from the command\nline.\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\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) request to the Speech-to-Text API.\n\nOpen the command line shell and run the following command. \n\n```bash\ngcloud ml speech recognize gs://cloud-samples-tests/speech/brooklyn.flac \\\n --language-code=en-US\n```\n\nThis command requests that Speech-to-Text transcribe\nthe audio contained in a [FLAC](/speech/docs/encoding) hosted at\na publicly accessible location.\n\nIf the request is successful, the server returns a response in\nJSON format: \n\n```text\n{\n \"results\": [\n {\n \"alternatives\": [\n {\n \"confidence\": 0.9840146,\n \"transcript\": \"how old is the Brooklyn Bridge\"\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"]]