File size: 6,163 Bytes
f2dc0dc 635ad5b b17db49 72a81f7 e308054 bde0ed3 a5ae5d4 bde0ed3 e308054 b17db49 e308054 bde0ed3 e308054 bde0ed3 b17db49 bde0ed3 b17db49 bde0ed3 b17db49 bde0ed3 b17db49 bde0ed3 b17db49 bde0ed3 b17db49 bde0ed3 a5ae5d4 bde0ed3 a5ae5d4 bde0ed3 b17db49 bde0ed3 a5ae5d4 bde0ed3 b17db49 bde0ed3 81a8e03 bde0ed3 b17db49 bde0ed3 b17db49 bde0ed3 b17db49 bde0ed3 81a8e03 bde0ed3 e308054 bde0ed3 e308054 635ad5b b17db49 635ad5b bde0ed3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Biryani Hub - Voice Login & Register</title>
<script>
let recognition;
let nameCaptured = "";
let emailCaptured = "";
let mobileCaptured = "";
if ('webkitSpeechRecognition' in window) {
recognition = new webkitSpeechRecognition();
recognition.continuous = false;
recognition.interimResults = false;
recognition.lang = 'en-US';
} else {
alert("Speech Recognition API not supported in this browser.");
}
function speak(text, callback) {
const speech = new SpeechSynthesisUtterance(text);
speech.onend = callback;
window.speechSynthesis.speak(speech);
}
function askLoginOrRegister() {
speak("Are you a new customer or an existing customer?", function() {
recognition.start();
recognition.onresult = function(event) {
let response = event.results[0][0].transcript.trim().toLowerCase();
recognition.stop();
if (response.includes("new")) {
checkIfUserExists();
} else if (response.includes("existing")) {
showLoginForm();
} else {
speak("Please say 'new' for registration or 'existing' for login.", askLoginOrRegister);
}
};
});
}
function checkIfUserExists() {
var email = document.getElementById('email').value;
var phone = document.getElementById('mobile').value;
fetch('/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email: email, phone_number: phone })
})
.then(response => response.json())
.then(data => {
if (data.success) {
speak("You are already registered. Logging you in now.");
autoLoginSubmit();
} else {
speak("Please provide your details for registration.");
showRegistrationForm();
}
});
}
function showRegistrationForm() {
speak("Please tell me your name.", startListeningForName);
}
function startListeningForName() {
recognition.start();
recognition.onresult = function(event) {
nameCaptured = event.results[0][0].transcript.trim();
document.getElementById('name').value = nameCaptured;
recognition.stop();
speak("You said " + nameCaptured + ". Is it correct?", confirmName);
};
}
function confirmName() {
recognition.start();
recognition.onresult = function(event) {
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
recognition.stop();
if (confirmation.includes("ok")) {
speak("Now, tell me your email.", startListeningForEmail);
} else {
speak("Let's try again. Tell me your name.", startListeningForName);
}
};
}
function startListeningForEmail() {
recognition.start();
recognition.onresult = function(event) {
emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
document.getElementById('email').value = emailCaptured;
recognition.stop();
speak("You said " + emailCaptured + ". Is it correct?", confirmEmail);
};
}
function confirmEmail() {
recognition.start();
recognition.onresult = function(event) {
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
recognition.stop();
if (confirmation.includes("ok")) {
speak("Now, tell me your mobile number.", startListeningForMobile);
} else {
speak("Let's try again. Tell me your email.", startListeningForEmail);
}
};
}
function startListeningForMobile() {
recognition.start();
recognition.onresult = function(event) {
mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
document.getElementById('mobile').value = mobileCaptured;
recognition.stop();
speak("You said " + mobileCaptured + ". Is it correct?", confirmMobile);
};
}
function confirmMobile() {
recognition.start();
recognition.onresult = function(event) {
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
recognition.stop();
if (confirmation.includes("ok")) {
autoSubmit();
} else {
speak("Let's try again. Tell me your mobile number.", startListeningForMobile);
}
};
}
function autoSubmit() {
fetch('/submit', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: nameCaptured, email: emailCaptured, phone: mobileCaptured })
})
.then(response => response.json())
.then(data => {
if (data.success) {
speak("Registration complete. Thank you!");
} else {
speak(data.message);
}
});
}
window.onload = function () {
askLoginOrRegister();
};
</script>
</head>
<body>
</body>
</html>
|