DEV Community


Exclusive : Text to speech (tts) in javascript! (Damn easy)

Raghav Yadav
var Coder => (){ ”always” = true; }
Updated on ・1 min read

Hi guys I'm back with a new tutorial and in this tutorial I will show you how to you have speech synthesis in your web application!

First include the cdna of hash.JS in your HTML heading tag:

<script src=""></script>
Enter fullscreen mode Exit fullscreen mode

And then simply you can read the message by the following syntax:

hash().read("hi there, this is text to speech!");
Enter fullscreen mode Exit fullscreen mode

Else use this:

function read(message){
  const speech = new SpeechSynthesisUtterance();
  speech.text = message;
  speech.volume = 1;
  speech.rate = 1;
  speech.pitch = 1;
Enter fullscreen mode Exit fullscreen mode

Yes! it's that easy?
and if you enjoyed the article you shouldn't forget to hit a like and if you think that this article was unique hit the unicorn also!

Discussion (3)

beyond5575 profile image

Some comments have been hidden by the post's author - find out more

Forem Open with the Forem app