- Lab
- A Cloud Guru
Setting Up Google Cloud Text-to-Speech
Although there are many tools to communicate, there are two basic types of communication: written and spoken. Machine learning has made it possible to convert one to the other, resulting in speech that is very close to that of a human voice. In this hands-on lab, you'll step through the process for utilizing the Google Cloud Text-to-Speech API, transforming text in a JSON format to an audio-ready MP3 file.
Path Info
Table of Contents
-
Challenge
Enable the Cloud Text-to-Speech API
- From the Google Cloud console's main navigation, choose APIs & Services > Library.
- Search for "text", and select Cloud Text-to-Speech API.
- If necessary, click Enable.
-
Challenge
Set Up Service Account
-
Click Launch Editor.
-
In the Shell Editor, expand the ai-conversations folder.
-
Choose File > New File and name the file
key.json
. -
From this Hands-On Lab Credentials, copy the Service Account Credentials.
-
Paste the clipboard contents into the new file, and choose File > Save.
-
Switch to the Terminal enter the following command:
export GOOGLE_APPLICATION_CREDENTIALS=key.json
-
-
Challenge
Retrieve Working Files
-
Activate the Cloud Shell.
-
Retrieve the working files:
git clone https://github.com/linuxacademy/content-gc-ai-services-deepdive
-
In the Cloud Shell, change directories:
cd content-gc-ai-services-deepdive/ai-conversations/
-
-
Challenge
Send Request to Cloud Text-to-Speech API
-
Call the Cloud Text-to-Speech API:
curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) -H "Content-Type: application/json; charset=utf-8" -d @text-to-speech-request.json https://texttospeech.googleapis.com/v1/text:synthesize > synthesize-text.txt
-
In the Shell Editor, open
synthesize-text.txt
. -
Remove the following from the beginning of the file:
{ "audioContent": "
-
From the end of the file, remove the following:
" }
-
Save the file.
-
-
Challenge
Convert Response to MP3
-
In the Cloud Shell, enter the following command:
base64 synthesize-text.txt -d > synthesized-audio.mp3
-
Download the MP3 file to your system:
cloudshell download synthesized-audio.mp3
-
Click Download.
-
Open the downloaded MP3 file to hear the results.
-
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.