JSFiddle - React, Tailwind, and code Playground
by velo_ninja
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text-to-Speech Example</title>
</head>
<body>
<div>
<label for="textToSpeech">Enter text to convert to speech:</label>
<input type="text" id="textToSpeech" placeholder="Enter text">
<button onclick="speak()">Speak</button>
</div>
<script>
function speak() {
const textToSpeech = document.getElementById('textToSpeech').value.trim();
if (textToSpeech) {
const synth = window.speechSynthesis;
const utterance = new SpeechSynthesisUtterance(textToSpeech);
synth.speak(utterance);
} else {
alert('Please enter text to convert to speech.');
}
}
</script>
</body>
</html>