Create audio from text by using client libraries
This quickstart walks you through the process of using client libraries to make a request to Cloud TTS, creating audio from text.
To learn more about the fundamental concepts in Cloud Text-to-Speech, read Cloud Text-to-Speech Basics. To see which synthetic voices are available for your language, see the supported voices and languages page.
Before you begin
Before you can send a request to the Cloud Text-to-Speech API, you must have completed the following actions. See the before you begin page for details.
- Enable Cloud Text-to-Speech on a Google Cloud project.
- Make sure billing is enabled for Cloud Text-to-Speech.
-
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud initIf you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
Install the client library
Go
go get cloud.google.com/go/texttospeech/apiv1
Java
If you are using Maven, add
the following to your pom.xml file. For more information about
BOMs, see The Google Cloud Platform Libraries BOM.
If you are using Gradle, add the following to your dependencies:
If you are using sbt, add the following to your dependencies:
If you're using Visual Studio Code or IntelliJ, you can add client libraries to your project using the following IDE plugins:
The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.
Node.js
Before installing the library, make sure you've prepared your environment for Node.js development.
npm install @google-cloud/text-to-speech
Python
Before installing the library, make sure you've prepared your environment for Python development.
pip install --upgrade google-cloud-texttospeech
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the Cloud TTS reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Cloud TTS reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Cloud TTS reference documentation for Ruby.
Create audio data
Now you can use Cloud TTS to create an audio file
of synthetic human speech. Use the following code to send a
synthesize request to the Cloud Text-to-Speech API.
Go
Java
Node.js
Before running the example, make sure you've prepared your environment for Node.js development.
Python
Before running the example, make sure you've prepared your environment for Python development.
Congratulations! You've sent your first request to Cloud Text-to-Speech.
How did it go?
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
- Use the Google Cloud console to delete your project if you don't need it.
What's next
- Learn more about Cloud Text-to-Speech by reading the basics.
- Review the list of available voices you can use for synthetic speech.