text_to_speech
Category

How to convert text to speech in Javascript.

Recently in one of my projects, I got to know about this beautiful API of Javascript. Using this you can make your application speak. This API is native to javascript which means you need not include any third-party library to make it work.

Let me show how it works programmatically.

<button class="press" onclick="press()">Press Me</button>
<script>
    function press() {
        const text = "How you doing !!";
        const utterance = new SpeechSynthesisUtterance(text);
        utterance.pitch = 1.5;
        window.speechSynthesis.speak(utterance);  
    }
</script>

Here is the link to the full code

https://gist.github.com/braniac007/19c270cf05e0b2d7c8425c64d6dd1af8

And here is the live example link

https://codedomino.com/examples/text_to_speech.html

Happy Coding 🫶

Leave a Reply

Your email address will not be published. Required fields are marked *