The speech synthesis is used to convert given text to speech. We can implement this feature in nodejs application with npm package available called 'say'.
The voice parameter and speed in the function say
not available means it will use the default system voice, ignoring the voice and speed parameter.
create a folder and type below command to create package.json file
npm init --yes
Once above code run successfully then install required packages.
npm install body-parser express say --save
After that, We will start the app and create the method to take text as input and convert it to speech. Now create a file server.js and put below code in it.
Now run the application over terminal by entering node server.js
And text it over postman like below:
You can use any tool you want to test this api.
While checking the API, if you are getting error like below over terminal:
Error: spawn festival ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:201:19)
at onErrorNT (internal/child_process.js:379:16)
at process._tickCallback (internal/process/next_tick.js:114:19)
Then install a dependency needed here with below command:
sudo apt-get install festival festvox-kallpc16k
That’s all for now. Thank you for reading and I hope this article will be very helpful to understand the text to speech in Node.js.
Let me know your thoughts over the email demo.jsonworld@gmail.com. I would love to hear them and If you like this article, share with your friends.