Before You Begin

Stay organized with collections Save and categorize content based on your preferences.

Text-to-Speech is an API that is powered by Google's artificial intelligence (AI) technology. You send your transcript data to Text-to-Speech in an API call, then receive natural-sounding, synthetic human speech as playable audio in response. For more information on how Text-to-Speech works, see the basics page.

We provide code samples that show you how to make a request to the API and receive a response. You can learn how to use these samples by following the Text-to-Speech quickstarts and how-to guides.

This guide walks you through the steps necessary to start sending requests to the Text-to-Speech API.


Before you can begin using Text-to-Speech, you must enable the API in the Google Cloud Platform Console. The steps below walk you through the following actions:

  • Enable Text-to-Speech on a project.
    1. Make sure billing is enabled for Text-to-Speech.
    2. Make sure your project has at least one service account.
    3. Download a service account credential key.
  • Set your authentication environment variable.

Set up your Google Cloud Platform project

  1. Sign in to Google Cloud console

  2. Go to the project selector page

    You can either choose an existing project or create a new one. For more details about creating a project, please see the Google Cloud Platform documentation.

  3. If you create a new project, you will be prompted to link a billing account to this project. If you are using a pre-existing project, make sure that you have billing enabled.

    Learn how to confirm that billing is enabled for your project

  4. Once you have selected a project and linked it to a billing account, you can enable the Text-to-Speech API. Go to the Search products and resources bar at the top of the page and type in "speech". Select the Cloud Text-to-Speech API from the list of results.

  5. To try Text-to-Speech without linking it to your project, choose the TRY THIS API option. To enable the Text-to-Speech API for use with your project, click ENABLE.

  6. You now must link one or more service accounts to the Text-to-Speech API. Click on the Credentials link on the left side of the Text-to-Speech API page:

    If you do not have any service accounts associated with this project, create one by following the instructions in the creating a new service account section.

    If you do have previously-created service accounts associated with this project, they will appear on this page. Make sure that you have access to a downloaded JSON key associated with the service account you'd like to use to authenticate with Text-to-Speech. Service account keys are downloadable only once, at the time they are created. If your service account has an existing key but you can't locate the downloaded .json file, you will need to create a new key for that service account and download its .json file. For instructions on how to create a new key on an existing service account, follow the instructions in the creating a JSON key section.

    If you already have a service account and its JSON key, you can now set your authentication environment variable.

Create a new service account

  1. Create a new service account if your project doesn't already have one. You must create a service account in order to use Text-to-Speech.

    Go to Create service account

    In the Service account name box, type a unique name for the new service account. Your input is automatically populated in the Service account ID box. The Service account description box is optional but recommended if you plan to associate multiple service accounts with your project. Enter a brief description of the service account into this box, then click CREATE AND CONTINUE.

  2. We recommend that you assign one of the basic IAM roles to your service account. You can also assign multiple roles to a single service account if needed. See IAM roles for details on available roles and the permissions allowed to each. Click on the drop-down Select a role menu and scroll down to Basic. You can choose a role for this service account from the options that appear in the right-hand column. Click CONTINUE.

  3. The final step allows you to optionally allow other entities (individuals, Google groups, and so on) to access your service account. If you don't need to grant additional access, you can click DONE without entering any information.

  4. The service account is now listed on the Service Accounts page. You can change the service account's permissions, add or generate new keys, and grant access at any time.

Create a JSON key for your service account

  1. The newly-created service account appears on the service accounts page. Create a private key that will be associated with that account. You need to use this private key during the authentication process when you send a request to Text-to-Speech. If you choose not to create a key now, you can generate a key and/or change individual user information at any time by accessing the service account through the IAM & Admin -> Service Accounts option in the main navigation menu.

    To create a key, click on the service account and select KEYS. Click ADD KEY -> Create new key. We recommend that you create a key in JSON format.

  2. A new key in the format of your choice is automatically downloaded. Store this file in a safe location and make a note of the file path. You will need to point the GOOGLE_APPLICATION_CREDENTIALS environment variable to this file when you go through the authentication process at the beginning of each new Text-to-Speech session. This is an essential step for authenticating requests to Text-to-Speech. The key's unique ID appears next to the name of the service account.

Set your authentication environment variable

In order to set your GOOGLE_APPLICATION_CREDENTIALS, you must have a service account associated with your project and have access to the service account's JSON key.

Provide authentication credentials to your application code by setting the environment variable GOOGLE_APPLICATION_CREDENTIALS. This variable applies only to your current shell session. If you want the variable to apply to future shell sessions, set the variable in your shell startup file, for example in the ~/.bashrc or ~/.profile file.

Linux or macOS


Replace KEY_PATH with the path of the JSON file that contains your service account key.

For example:

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"


For PowerShell:


Replace KEY_PATH with the path of the JSON file that contains your service account key.

For example:


For command prompt:


Replace KEY_PATH with the path of the JSON file that contains your service account key.

For more information, see the Google Cloud Platform authentication documentation.

Disable the Text-to-Speech API

To disable the Text-to-Speech API, navigate to your Google Cloud Platform dashboard and click on the Go to APIs overview link in the APIs box. Click on the Text-to-Speech API, then select the DISABLE API button at the top of the page.

What's next

Learn how to send a transcription request to the Text-to-Speech API using client libraries or the command line.