Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to convert text to speech in Node.js ?

  • Last Updated : 19 May, 2020

To convert text to speech in Node.js, there are various modules but the most popular among them is gtts
(Google Text to Speech) module.

Feature of gtts module:

  1. It is easy to get started and easy to use.
  2. It is widely used and popular for converting text to speech.

Installation of gtts module:

  1. You can visit the link to Install gtts module. You can install this package by using this command.
    npm install gtts
  2. After installing gtts module, you can check your gtts version in command prompt using the command.
    npm version gtts
  3. After that, you can create a folder and add a file, for example index.js. To run this file you need to run the following command.
    node index.js

Filename: index.js

const gTTS = require('gtts');
var speech = 'Welcome to GeeksforGeeks';
var gtts = new gTTS(speech, 'en');'Voice.mp3', function (err, result){
    if(err) { throw new Error(err); }
    console.log("Text to speech converted!");

Steps to run the program:

  1. The project structure will look like this:
    project structure
  2. Make sure you have installed gtts module using the following commands:
    npm install gtts
  3. Run index.js file using below command:
    node index.js

    Output of above command

  4. After running above command, your text is converted to speech and save in your Voice.mp3 file as shown below:
    Output of above command

So this is how you can use the gtts (Google Text to Speech) module for converting text to speech in Node.js.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!