Spaces:
Sleeping
Sleeping
File size: 8,066 Bytes
cd2c91d 7547860 c065c92 e748187 1ea5871 86b7bfb 4539c80 75ec2d8 24a1541 75ec2d8 24a1541 1ea5871 24a1541 75ec2d8 24a1541 1ea5871 24a1541 b0082be 24a1541 b0082be 24a1541 e8c85cc 24a1541 75ec2d8 24a1541 e8c85cc 24a1541 e8c85cc e748187 7547860 8fdce7e b0082be 24a1541 c065c92 3e2a505 7a88679 24a1541 c065c92 75ec2d8 b0082be ce5c734 24a1541 c065c92 75ec2d8 24a1541 75ec2d8 c065c92 24a1541 b0082be c065c92 24a1541 c065c92 24a1541 c065c92 75ec2d8 24a1541 c065c92 75ec2d8 c065c92 75ec2d8 24a1541 75ec2d8 c065c92 24a1541 c065c92 24a1541 c065c92 75ec2d8 24a1541 75ec2d8 ce5c734 b0082be 7547860 75ec2d8 |
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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Biryani Hub Menu</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f8f8f8;
margin: 0;
padding: 0;
}
.menu-container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
margin-top: 50px;
}
h1 {
text-align: center;
font-size: 2.5rem;
color: #333;
margin-bottom: 30px;
}
.menu-item {
border-bottom: 1px solid #eee;
padding: 15px 0;
display: flex;
justify-content: space-between;
align-items: center;
}
.order-btn {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.order-btn:hover {
background-color: #45a049;
}
#listen-btn {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1.2rem;
display: block;
margin: 30px auto;
}
#listen-btn:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="menu-container">
<h1>Welcome to the Menu</h1>
<!-- Dynamic Menu Item List -->
<div id="menu-items">
<!-- Menu items will be populated here from the backend -->
</div>
<button id="listen-btn">Say "Order" to order an item</button>
<div id="cart-summary" style="display:none;">
<h2>Your Cart:</h2>
<div id="cart-details"></div>
<button id="place-order-btn">Place Final Order</button>
</div>
</div>
<script>
const listenButton = document.getElementById("listen-btn");
const placeOrderButton = document.getElementById("place-order-btn");
const cartSummary = document.getElementById("cart-summary");
const cartDetails = document.getElementById("cart-details");
let isListening = false;
let cart = []; // Global cart variable to store items
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
recognition.lang = "en-US";
recognition.interimResults = false;
// Function to speak text
function speak(text) {
const msg = new SpeechSynthesisUtterance(text);
window.speechSynthesis.speak(msg);
}
listenButton.addEventListener("click", () => {
if (!isListening) {
isListening = true;
speak("Please say the item you want to order.");
recognition.start();
}
});
recognition.onresult = (event) => {
const command = event.results[0][0].transcript.toLowerCase();
console.log("User said:", command);
// Add logic to recognize specific items or trigger actions based on the command
if (command.includes("order")) {
// Process ordering logic here (e.g., find item in menu and add to cart)
processOrder();
} else if (command.includes("cart details")) {
showCartDetails();
} else {
speak("Sorry, I couldn't understand that. Please try again.");
}
};
recognition.onerror = (event) => {
console.error("Speech recognition error:", event.error);
speak("Sorry, I couldn't understand that. Please try again.");
};
// Function to process order
function processOrder() {
speak("Which item would you like to order?");
recognition.start();
recognition.onresult = (event) => {
const itemName = event.results[0][0].transcript.toLowerCase();
const item = findItem(itemName);
if (item) {
speak(`You selected ${item.name}. How many would you like?`);
recognition.start();
recognition.onresult = (event) => {
const quantity = parseInt(event.results[0][0].transcript);
if (quantity) {
addToCart(item, quantity);
speak(`${quantity} ${item.name} added to your cart.`);
askMoreItems();
} else {
speak("Please say a valid quantity.");
}
};
} else {
speak("Sorry, I couldn't find that item. Please try again.");
}
};
}
// Function to ask if the user wants to order more items
function askMoreItems() {
speak("Would you like to order more items?");
recognition.start();
recognition.onresult = (event) => {
const response = event.results[0][0].transcript.toLowerCase();
if (response.includes("yes")) {
processOrder();
} else {
showCartDetails();
}
};
}
// Function to show cart details
function showCartDetails() {
if (cart.length > 0) {
let cartHtml = "";
cart.forEach(item => {
cartHtml += `<p>${item.quantity} x ${item.name} - ₹${item.price * item.quantity}</p>`;
});
cartDetails.innerHTML = cartHtml;
cartSummary.style.display = "block";
speak(`Your cart contains ${cart.length} items.`);
} else {
speak("Your cart is empty.");
}
}
// Function to add an item to the cart
function addToCart(item, quantity) {
cart.push({ name: item.name, price: item.price, quantity: quantity });
}
// Function to find item in the menu
function findItem(itemName) {
const menu = [
{ name: "Chicken Biryani", price: 250 },
{ name: "Veg Biryani", price: 200 },
{ name: "Mutton Biryani", price: 300 }
];
return menu.find(item => item.name.toLowerCase() === itemName.toLowerCase());
}
// Function to populate the menu dynamically and speak it on load
window.onload = function() {
const menuItems = [
{ name: "Chicken Biryani", price: 250 },
{ name: "Veg Biryani", price: 200 },
{ name: "Mutton Biryani", price: 300 }
];
let menuContent = "";
menuItems.forEach(item => {
menuContent += `
<div class="menu-item">
<div class="details">
<h3>${item.name}</h3>
<p class="price">Price: ₹${item.price}</p>
</div>
<button class="order-btn" onclick="addToCart(${item.name}, 1)">Order</button>
</div>
`;
});
document.getElementById('menu-items').innerHTML = menuContent;
// Voice reading of menu items
let itemsText = "The menu includes: ";
menuItems.forEach(item => {
itemsText += item.name + ", ";
});
speak(itemsText); // Speak all the item names
}
</script>
</body>
</html>
|