DEV Community

Discussion on: Text To Speech In 3 Lines Of JavaScript

Collapse
 
josiasaurel profile image
Josias Aurel

I use Chrome and it's says my browser supports it

Thread Thread
 
lazaruswist profile image
lazarusWist • Edited

Check out MDN's speak easy synthesis demo which works on Chrome. There's two things you need to do to set it up properly:

1) As is the case with the Web Audio API generally, Chromium Browsers will not allow audio to be played without the user interacting with the page first. You need to put the speech synthesis code behind an event listener for some page event like a button click.

2) It seems that Chrome, unlike FireFox, does not have access to system voices when speechSynthesis is initialised for the first time. You need to add an event listener which refers to a function when the voices are found, something like - speechSynthesis.onvoiceschanged = getVoices. The technology is still experimental so I expect this will change in the future.