Last active
February 23, 2021 01:41
-
-
Save KrishnaPravin/827c667beabed476509e851e989d6f40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<p id="text">Waiting to start</p> | |
<script> | |
document.addEventListener('DOMContentLoaded', () => { | |
document.addEventListener('click', start); | |
const p = document.getElementById('text'); | |
const wait = (time = 1) => new Promise((r) => setTimeout(r, time * 1000)); | |
speechSynthesis.getVoices(); | |
const speak = (str) => { | |
p.innerHTML = str; | |
const k = new SpeechSynthesisUtterance(str); | |
k.voice = speechSynthesis.getVoices().find(({name}) => name === 'Veena'); | |
return window.speechSynthesis.speak(k); | |
}; | |
const fiveSeconds = async () => { | |
for (let i = 5; i; i--) { | |
speak(i); | |
await wait(); | |
} | |
}; | |
async function start() { | |
document.removeEventListener('click', start); | |
speak('Starting In 10 seconds...'); | |
await wait(5); | |
await fiveSeconds(); | |
for (let i = 1; i <= 10; i++) { | |
speak('round ' + i); | |
await wait(15); | |
await fiveSeconds(); | |
if (i === 10) continue; | |
await fiveSeconds(); | |
} | |
speak('Congratulations!!!'); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment