This quickstart introduces you to Text-to-Speech. In this quickstart, you set up your Google Cloud Platform project and authorization and then make a request for Text-to-Speech to create audio from text.
To learn more about the fundamental concepts in Text-to-Speech, read Text-to-Speech Basics.
Before you begin
-
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
-
In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.
- Enable the Cloud Text-to-Speech API.
-
Set up authentication:
-
In the Cloud Console, go to the Create service account key page.
Go to the Create Service Account Key page - From the Service account list, select New service account.
- In the Service account name field, enter a name.
- Don't select a value from the Role list. No role is required to access this service.
- Click Create. A note appears, warning that this service account has no role.
- Click Create without role. A JSON file that contains your key downloads to your computer.
-
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again. - Install and initialize the Cloud SDK.
Install the client library
C#
Install-Package Google.Cloud.TextToSpeech.V1 -Pre
Go
go get -u cloud.google.com/go/texttospeech/apiv1
Java
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
PHP
composer require 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
Ruby
gem install google-cloud-text_to_speech
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.
C#
Go
Java
Node.js
Before running the example, make sure you've prepared your environment for Node.js development.
PHP
Python
Before running the example, make sure you've prepared your environment for Python development.
Ruby
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 in this quickstart, follow these steps.
- Use the 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.