How To Convert Text To Speech & Stream In node.js

The speech synthesis is utilized to change over composed data into sound where it is more helpful for people. Albeit such a highlights is extraordinarily utilized in portable applications, for example, voice-empowered email and bound together informing applications, you can carry out an extremely basic TTS system in Node.js utilizing the ‘gtts’ module.

There are various method of TTS like Say, text-to-speech-js, gtts and many other , Gtts is a interface to google’s text to speech API. It takes into account limitless lengths of spoken content by tokenizing long sentences where the discourse would normally stop.

Installation

You may reach at gtts.js, You can use this module by using below command

There are two method to use this module

Save Method

It will permit you to save you record according to given location, Create index.js and save below code

To run use node index.js command

Stream Method

This strategy will permit you to run continuous , However you will pass text paramter in URL, it will change text over to speech. For which you have to install express module as well

Create an route , As hear it’s defined here

const express = require('express'); const app = express(); const Gtts = require('gtts'); app.get('/hear', { const gtts = new Gtts(req.query.text, req.query.lang); gtts.stream().pipe(res); }); app.listen(3000, { console.log('Open url to hear voice http://localhost:3000/hear?lang=en&text=My Name is shantun, Nice meeting you'); });

So this is the way by which you can utilize the gtts (Google Text to Speech) module for changing text over to speech in Node.js.

Thanks for reading , See you in next article

Take care

Originally published at https://shantun.hashnode.dev.

--

--

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