javascript – How to voice the text on the site?

Question:

I can't find a suitable one. Help if you know.

I need to say the words. That is, when the user clicks on the button, only one word is spoken.

If anyone knows how, please share an example.

PS: the voice acting is in English.

Answer:

An example of playing sound through js:

function speak() {
    let text = document.getElementById('text').value;
    speechSynthesis.speak(new SpeechSynthesisUtterance(text));
}
speak();
<meta charset="utf-8">
<p>Воспроизвести звуки.
<input id="text">
<button onclick="speak();">Произнести вслух</button>
Scroll to Top