# Transcribe speech to text by using the gcloud CLI

This page shows you how to send a speech recognition request to Cloud Speech-to-Text
by using the [`gcloud`](https://docs.cloud.google.com/sdk/gcloud/reference/ml/speech) 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 Cloud Speech-to-Text API, which then returns a
text transcription of that audio file. For more information about
the service, see
[Cloud STT basics](https://docs.cloud.google.com/speech-to-text/docs/basics).

## Before you begin

Before you can send a request to the Cloud Speech-to-Text API, you must complete
the following actions.

1. Optional: Create a new Cloud Storage bucket to store your audio data. For more information, see [Create a Cloud Storage bucket](https://docs.cloud.google.com/speech-to-text/docs/setup.md.txt#create-gcs-bucket).

<br />

For more information about enabling the API, see
[Set up Cloud Speech-to-Text for your Google Cloud project](https://docs.cloud.google.com/speech-to-text/docs/setup.md.txt).

### Required roles


To ensure that Cloud Composer Service Agent has the necessary
permissions to run Cloud Speech-to-Text,

ask your administrator to grant the
Service Account Token Creator (`iam.serviceAccountTokenCreator`)
IAM role to Cloud Composer Service Agent on your project.


**Important:** You must grant this role to Cloud Composer Service Agent, *not* to your user account. Failure to grant the role to the correct principal might result in permission errors. For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).

<br />


Your administrator might also be able to give Cloud Composer Service Agent
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).


To get the permissions that
you need to store audio in Cloud Storage,

ask your administrator to grant you the
[Storage Object Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/storage.md.txt#storage.objectViewer) (`roles/storage.objectViewer`) IAM role on Cloud Storage bucket.


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

## Make an audio transcription request

Use Cloud STT to transcribe an audio file to text. Use the
following code sample to send a [`recognize`](https://docs.cloud.google.com/speech-to-text/docs/reference/rest/v1/speech/recognize.md.txt) request to the
Cloud Speech-to-Text API.

Open the command line shell and run the following command.

```bash
gcloud ml speech recognize gs://cloud-samples-tests/speech/brooklyn.flac \
    --language-code=en-US
```

This command requests that Cloud STT transcribe the audio contained
in a [FLAC](https://docs.cloud.google.com/speech-to-text/docs/v1/encoding) 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 sent your first request to Cloud STT.


If you receive an error or an empty response from
Cloud STT, take a look at the
[troubleshooting](https://docs.cloud.google.com/speech-to-text/docs/troubleshooting.md.txt) and
[error mitigation](https://docs.cloud.google.com/speech-to-text/docs/error-messages) steps.

## Clean up


To avoid incurring charges to your Google Cloud account for
the resources used on this page, delete the Google Cloud project with the
resources.

- Use the [Google Cloud console](https://console.cloud.google.com/) to delete your project if you don't need it.

## What's next


- Practice [transcribing short audio files](https://docs.cloud.google.com/speech-to-text/docs/sync-recognize.md.txt).
- Learn how to [batch long audio files for speech recognition](https://docs.cloud.google.com/speech-to-text/docs/async-recognize).
- Learn how to [transcribe streaming audio](https://docs.cloud.google.com/speech-to-text/docs/streaming-recognize.md.txt) like from a microphone.
- Get started with the Cloud STT in your language of choice by using a [Cloud STT client library](https://docs.cloud.google.com/speech-to-text/docs/reference/libraries).
- Work through the [sample applications](https://docs.cloud.google.com/speech-to-text/docs/samples.md.txt).
- For best performance, accuracy, and other tips, see the [best practices](https://docs.cloud.google.com/speech-to-text/docs/best-practices.md.txt) documentation.

<br />