The Google Cloud Speech API enables easy integration of Google speech recognition technologies into developer applications. The Speech API allows you to send audio and receive a text transcription from the service (see What is the Google Cloud Speech API? for more information).

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 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. Install and initialize the Cloud SDK.
  4. Provide authentication credentials to your application code by running the following command. Replace [PATH] with the location of the JSON file that contains your credentials.

    gcloud auth activate-service-account --key-file=[PATH]

Make a Speech API request

In this step, you make a Speech API Request using the recognize REST method.

  1. Create a JSON request file with the following text, and save it as a sync-request.json plain text file:

      "config": {
          "sampleRateHertz": 16000,
          "languageCode": "en-US",
          "enableWordTimeOffsets": false
      "audio": {

    This JSON snippet indicates that the audio file has a FLAC encoding format, a sample rate of 16000 Hz, and that the audio file is stored on Google Cloud Storage at the given URI. The audio file is publicly accessible, so you don't need authentication credentials to access the file.

  2. Use curl to make a speech:recognize request, passing it the filename of the JSON request you set up in step 1:

    The sample curl command uses the gcloud auth print-access-token command to get an authentication token.

    curl -s -H "Content-Type: application/json" \
        -H "Authorization: Bearer "$(gcloud auth print-access-token) \
        https://speech.googleapis.com/v1/speech:recognize \
        -d @sync-request.json

    Note that to pass a filename to curl you use the -d option (for "data") and precede the filename with an @ sign. This file should be in the same directory in which you execute the curl command.

    You should see a response similar to the following:

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

Congratulations! You've sent your first request to the Cloud Speech API!

What's next

Send feedback about...

Google Cloud Speech API Documentation