Skip to content

Instantly share code, notes, and snippets.

@KrishnaPravin
Last active February 23, 2021 01:41
Show Gist options
  • Save KrishnaPravin/827c667beabed476509e851e989d6f40 to your computer and use it in GitHub Desktop.
Save KrishnaPravin/827c667beabed476509e851e989d6f40 to your computer and use it in GitHub Desktop.
<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