Tutorial for using Google TTS API on Node.js project

Create a Google Cloud Project.

refer ‘Creating a service account’ section on this official guide
https://cloud.google.com/docs/authentication/getting-started

But, you don’t need the other part.

If you have done to make a new project and downloaded the credential file, store as secure.

I had located the file to here.

/keys/Speech-...

Install Libraries what you need

We need these modules

@google-cloud/text-to-speech
dotenv
lodash

So, execute this

npm i @google-cloud/text-to-speech dotenv lodash

Set the .env file

write a credential location into the .env file.

GOOGLE_APPLICATION_CREDENTIALS=“[your location]”

Write and try the main code

original reference: https://www.woolha.com/tutorials/node-js-google-cloud-text-to-speech-api-examples

So, you could get a listenable mp3 file

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store