Spaces:
Runtime error
Runtime error
Create static/script.js
Browse files- static/script.js +46 -0
static/script.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 2 |
+
const synth = window.speechSynthesis;
|
| 3 |
+
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
| 4 |
+
recognition.continuous = false;
|
| 5 |
+
recognition.interimResults = false;
|
| 6 |
+
recognition.lang = 'en-US';
|
| 7 |
+
|
| 8 |
+
const speak = (text, callback) => {
|
| 9 |
+
const utterance = new SpeechSynthesisUtterance(text);
|
| 10 |
+
utterance.onend = callback;
|
| 11 |
+
synth.speak(utterance);
|
| 12 |
+
};
|
| 13 |
+
|
| 14 |
+
const startRecognition = (callback) => {
|
| 15 |
+
recognition.start();
|
| 16 |
+
recognition.onresult = (event) => {
|
| 17 |
+
const transcript = event.results[0][0].transcript;
|
| 18 |
+
callback(transcript);
|
| 19 |
+
recognition.stop();
|
| 20 |
+
};
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
const welcomeMessage = () => {
|
| 24 |
+
speak("Welcome to Biryani Hub. Tell me your name.", () => {
|
| 25 |
+
startRecognition((name) => {
|
| 26 |
+
document.getElementById('username').value = name;
|
| 27 |
+
askEmail();
|
| 28 |
+
});
|
| 29 |
+
});
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
const askEmail = () => {
|
| 33 |
+
speak("Please provide your email address.", () => {
|
| 34 |
+
startRecognition((email) => {
|
| 35 |
+
document.getElementById('email').value = email;
|
| 36 |
+
speak("Thank you. Your email has been registered.", () => {
|
| 37 |
+
setTimeout(() => {
|
| 38 |
+
location.reload();
|
| 39 |
+
}, 20000);
|
| 40 |
+
});
|
| 41 |
+
});
|
| 42 |
+
});
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
welcomeMessage();
|
| 46 |
+
});
|