Node.js Express Text to Speech Audio in Mp3 in Various Languages Using GTTS Library Full Tutorial 2020

Node.js Express Text to Speech Audio in Mp3 in Various Languages Using GTTS Library Full Tutorial 2020





Live Demo



You can see the live demo of the web app here



Get Started


In order to get started you need to install three dependencies given below


npm i express


npm i nodemon


npm i gtts



After installing this make the html of the application shown below



<div class="col-md-4 col-sm-6 col-xs-12">
    <div class="content colour-1">
      <h3 class="text-center">Text To Speech Demo</h3>
      <div class="text-center">
        <a class="btn btn-danger" href="/texttospeechdemo">Convert Now</a>



<!DOCTYPE html>
    <title>Text to Speech Demo</title>
      <div class="container">
          <h1 class="text-center">
              Text to Speech Demo
          <form action="/texttospeechdemo" method="post">
            <div class="form-group">
                <label for="text">Text:</label>
                <textarea class="form-control" name="text" id="" cols="30" rows="10"></textarea>
            <div class="form-group">
                <label for="format">Select Language of Voice:</label>
                <select class="form-control" name="language" id="">
                    <option value="af" selected>Afrikaans</option>
                    <option value="sq">Albanian</option>
                    <option value="ar">Arabic</option>
                    <option value="hy">Armenian</option>
                    <option value="ca">Catalan</option>
                    <option value="zh">Chinese</option>
                    <option value="zh-cn">Chinese (Mandarin/China)</option>
                    <option value="zh-tw">Chinese (Mandarin/Taiwan)</option>
                    <option value="zh-yue">Chinese (Cantonese)</option>
                    <option value="hr">Croatian</option>
                    <option value="cs">Czech</option>
                    <option value="da">Danish</option>
                    <option value="nl">Dutch</option>
                    <option value="en" selected>English</option>
                    <option value="en-au">English (Australia)</option>
                    <option value="en-uk">English (United Kingdom)</option>
                    <option value="en-us">English (United States)</option>
                    <option value="eo">Esperanto</option>
                    <option value="fi">Finnish</option>
                    <option value="fr">French</option>
                    <option value="de">German</option>
                    <option value="el">Greek</option>
                    <option value="ht">Haitian Creole</option>
                    <option value="hi">Hindi</option>
                    <option value="hu">Hungarian</option>
                    <option value="is">Icelandic</option>
                    <option value="id">Indonesian</option>
                    <option value="it">Italian</option>
                    <option value="ja">Japanese</option>
                    <option value="ko">Korean</option>
                    <option value="la">Latin</option>
                    <option value="lv">Latvian</option>
                    <option value="mk">Macedonian</option>
                    <option value="no">Norwegian</option>
                    <option value="pl">Polish</option>
                    <option value="pt">Portuguese</option>
                    <option value="pt-br">Portuguese (Brazil)</option>
                    <option value="ro">Romanian</option>
                    <option value="ru">Russian</option>
                    <option value="sr">Serbian</option>
                    <option value="sk">Slovak</option>
                    <option value="es">Spanish</option>
                    <option value="es-es">Spanish (Spain)</option>
                    <option value="es-us">Spanish (United States)</option>
                    <option value="sw">Swahili</option>
                    <option value="sv">Swedish</option>
                    <option value="ta">Tamil</option>
                    <option value="th">Thai</option>
                    <option value="tr">Turkish</option>
                    <option value="vi">Vietnamese</option>
                    <option value="cy">Welsh</option>
            <div class="form-group">
                <button class="btn btn-danger btn-block">
                    Download Audio File

  <script src=""></script>


See also  jsPDF Tutorial to Rotate Text at Different Angles or Directions in PDF Document Using Javascript Full Project For Beginners



const express = require("express");

const bodyParser = require("body-parser");

const gtts = require('gtts')

const fs = require("fs");

const app = express();

app.use(bodyParser.urlencoded({ extended: false }));

const PORT = process.env.PORT || 5000;

app.get('/texttospeechdemo',(req,res) => {
  res.render('texttospeechdemo',{title:"Text to Speech Demo - Free Media Tools"})
})'/texttospeechdemo',(req,res) => {
  var text = req.body.text

  var language = req.body.language

  outputFilePath = + "output.mp3"

  var voice = new gtts(text,language),function(err,result){
      res.send("Unable to convert to audio")
    },(err) => {
        res.send("Unable to download the file")


app.listen(PORT, () => {
  console.log(`App is listening on Port ${PORT}`);







Leave a Reply