menu_for_biryi / static /script.js
lokesh341's picture
Create static/script.js
0e1fb43 verified
document.addEventListener('DOMContentLoaded', function() {
const synth = window.speechSynthesis;
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
recognition.continuous = false;
recognition.interimResults = false;
recognition.lang = 'en-US';
const speak = (text, callback) => {
const utterance = new SpeechSynthesisUtterance(text);
utterance.onend = callback;
synth.speak(utterance);
};
const startRecognition = (callback) => {
recognition.start();
recognition.onresult = (event) => {
const transcript = event.results[0][0].transcript;
callback(transcript);
recognition.stop();
};
};
const welcomeMessage = () => {
speak("Welcome to Biryani Hub. Tell me your name.", () => {
startRecognition((name) => {
document.getElementById('username').value = name;
askEmail();
});
});
};
const askEmail = () => {
speak("Please provide your email address.", () => {
startRecognition((email) => {
document.getElementById('email').value = email;
speak("Thank you. Your email has been registered.", () => {
setTimeout(() => {
location.reload();
}, 20000);
});
});
});
};
welcomeMessage();
});