Take off Cloud Text-to-Speech API using Node.js

by user

This post is my memo about how Cloud Text-to-Speech API from Google uses

Take off Cloud Text-to-Speech API using Node.js

Create your project

First of all, you visit Google Cloud Platform and create and create a project.

Activate APIs

You select the library from API and Service beside home menu at the right side. Then turn on the following APIs

  • Cloud Text-to-Speech API
  • Cloud Speech API

As the Cloud Text-to-Speech API consists of charging system, you are required to register your credit card. You can choose free trial for free in 12 months. If you should overuse beyond free points, you never charge the extra cost under secret. So you can feel free to use. In case of surpass, Google notify some of information to you in advance.


The Cloud Text-to-Speech allow to use not more than 60 minutes(request) a month for free charging. Over the time, you will be charged for $0.006 per 15 seconds.

Install sox

So that you control voice audio in node.js you install sox library.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
brew install sox

Create project

Before starting, prepare a folder where you want and download sample code from Google. I customized it with following code.

Support Language is here

Create Service Account

You visit GCP Console and go to [API Manager] → [Credentials]. After the procedure [setup an API key] → [setup a service account], json file will be generated. Just put it in your directory.

Link path

Link GOOGLE_APPLICATION_CREDENTIALS variable into path. Go to your directory where you put the json file and type following command in terminal.

export GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_file>


Just run.

node index.js

Once I run the code, I got confusion because none of reactions was in my console. After few seconds the results analyzed strings from voices came out. Although I got the outcome, it was not yet somewhat realtime. Searching precise settings in the sample code, I found it.

interimResults: true

All you have to do is set interimResults true . You can see the progress in realtime.

Take off Cloud Text-to-Speech API using Node.js

You may also like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

Close Bitnami banner