Quickstart: Using the gcloud tool

This page shows you how to send a speech recognition request to Cloud Speech-to-Text using the gcloud tool from the command line.

Cloud Speech-to-Text enables easy integration of Google speech recognition technologies into developer applications. You can send audio data to the Speech-to-Text API, which then returns a text transcription of that audio file. For more information about the service, see Cloud Speech-to-Text basics.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Set up a GCP Console project.

    Set up a project

    Click to:

    • Create or select a project.
    • Enable the Cloud Speech-to-Text API for that project.
    • Create a service account.
    • Download a private key as JSON.

    You can view and manage these resources at any time in the GCP Console.

  3. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.

  4. Install and initialize the Cloud SDK.

Make an audio transcription request

Now you can use Cloud Speech-to-Text to transcribe an audio file to text. Use the following code sample to send a recognize request to the Speech-to-Text API.

Open the command line shell and run the following command.

gcloud ml speech recognize 'gs://cloud-samples-tests/speech/brooklyn.flac' \

This command requests that Cloud Speech-to-Text transcribe the audio contained in a FLAC hosted at a publicly accessible location.

If the request is successful, the server returns a response in JSON format:

  "results": [
      "alternatives": [
          "confidence": 0.9840146,
          "transcript": "how old is the Brooklyn Bridge"

Congratulations! You've sent your first request to Cloud Speech-to-Text.

If you receive an error or an empty response from Cloud Speech-to-Text, take a look at the troubleshooting and error mitigation steps.

What's next

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Speech-to-Text Documentation
Need help? Visit our support page.