Create audio from text by using client libraries
This quickstart walks you through the process of using client libraries to make a request to Text-to-Speech, creating audio from text.
To learn more about the fundamental concepts in Text-to-Speech, read 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 Text-to-Speech API, you must have completed the following actions. See the before you begin page for details.
- Enable Text-to-Speech on a Google Cloud project.
- Make sure billing is enabled for Text-to-Speech.
-
After installing the Google Cloud CLI, configure the gcloud CLI to use your federated identity and then initialize it by running the following command:
gcloud init
-
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, confirm that you have configured the gcloud CLI to use Workforce Identity Federation.
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, IntelliJ, or Eclipse, 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 --save @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 Text-to-Speech reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Text-to-Speech reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Text-to-Speech reference documentation for Ruby.
Create audio data
Now you can use Text-to-Speech to create an audio file
of synthetic human speech. Use the following code to send a
synthesize
request to the 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 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.