How can I utilize JavaScript to trigger Google TTS on a button click?

I am attempting to develop a JavaScript function that will read aloud specific text. For instance, I want to create something like this:

function ReadAloud(content) {
    // Your implementation
}

I came across a discussion that appears to have the solution I need, but my attempts to implement the suggestions have not been successful. Is it possible that HTML5 features are necessary for this to function correctly?

Could someone provide a straightforward JavaScript function that allows me to input text and have it spoken aloud?

You can use the Web Speech API for this. Here's a simple implementation:

function ReadAloud(content) {
    const utterance = new SpeechSynthesisUtterance(content);
    window.speechSynthesis.speak(utterance);
}

Include this function and trigger it with a button click:

<button onclick="ReadAloud('Your text here')">Read Aloud</button>

This should work in all modern browsers with HTML5 support.