-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
23 lines (19 loc) · 785 Bytes
/
Copy pathscript.js
File metadata and controls
23 lines (19 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const text = document.getElementById("textToConvert");
const convertBtn = document.getElementById("convertBtn");
convertBtn.addEventListener('click', function () {
const speechSynth = window.speechSynthesis;
const enteredText = text.value.trim();
if (!enteredText.length) {
alert(`Please enter some valid text to listen to the audio!`);
return; // Stop execution if there's no valid text
}
if (!speechSynth.speaking) {
const newUtter = new SpeechSynthesisUtterance(enteredText);
convertBtn.textContent = "Audio is playing...";
speechSynth.speak(newUtter);
newUtter.onend = () => {
// Reset button text when speech ends
convertBtn.textContent = "Speak what's written";
};
}
});