The Cloud Text To Speech API enables you to generate and customize synthesized speech from text or SSML.
These samples show how to list all supported voices, synthesize raw text, and synthesize a file.
To get started, download and install it.
-
Create a project with the Google Cloud Console, and enable the TextToSpeech API.
-
Set up authentication. For example, from the Cloud Console, create a service account, download its json credentials file, then set the appropriate environment variable:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json
-
Build the samples
mvn clean package
Synthesize text to an output audio file. Java Code
mvn exec:java -DQuickstart
This sample lists all the supported voices. Java Code
mvn exec:java -DListVoices
This sample synthesizes text to an output audio file. Java Code
mvn exec:java -DSynthesizeText -Dexec.args='--text "hello"'
This sample synthesizes text with an audio profile to an output audio file. Java Code
mvn exec:java -DSynthesizeText -Dexec.args='--text "hello" "telephony-class-application"'
This sample synthesizes ssml to an output audio file. Java Code
mvn exec:java -DSynthesizeText -Dexec.args='--ssml "<speak>Hello there.</speak>"'
This sample synthesizes a text file to an output audio file. Java Code
mvn exec:java -DSynthesizeFile -Dexec.args='--text resources/hello.txt'
This sample synthesizes a ssml file to an output audio file. Java Code
mvn exec:java -DSynthesizeFile -Dexec.args='--ssml resources/hello.ssml'