DEV Community

Discussion on: Text To Speech In 3 Lines Of JavaScript

Collapse
 
josiasaurel profile image
Josias Aurel

Unfortunately it didn't work for me

Collapse
 
asaoluelijah profile image
Asaolu Elijah šŸ§™ā€ā™‚ļø

Hi Josias,

Please note that the speechSynthesis API is not yet supported on all browsers.
The code below help you check for browser support:

if ('speechSynthesis' in window) {
 alert("Broswer supports speech synthesis šŸŽ‰");
}else{
  alert("Sorry, your browser doesn't support the speech synthesis API !");
}
Enter fullscreen mode Exit fullscreen mode
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.

Collapse
 
richardengle profile image
Richardengle

codepen.io/richardengle/pen/KKNzKXg is my version of this, combined with some hacks. try it :]

Collapse
 
tr11 profile image
Tiago Rangel

Link down! No archive available

Collapse
 
jcubic profile image
Jakub T. Jankiewicz

This is old but see my comment. You need to wait for voices to load.