Spaces:
Sleeping
Sleeping
<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 Biryani Hub</h1> | |
<h3 id="category-title">Please select a category:</h3> | |
<!-- Buttons for selecting categories --> | |
<div id="category-buttons"> | |
<button id="main-course-btn">Main Course</button> | |
<button id="appetizer-btn">Appetizers</button> | |
</div> | |
<!-- Dynamic Menu Item List --> | |
<div id="menu-items"></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"); | |
const categoryButtons = document.getElementById("category-buttons"); | |
let isListening = false; | |
let cart = []; // Global cart variable to store items | |
let menuData = {}; // Will store menu items based on categories | |
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")) { | |
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 populate the menu based on selected category | |
function displayMenuItems(category) { | |
const menuContainer = document.getElementById('menu-items'); | |
menuContainer.innerHTML = ''; // Clear previous menu | |
if (menuData[category]) { | |
menuData[category].forEach(item => { | |
const itemElement = document.createElement('div'); | |
itemElement.classList.add('menu-item'); | |
itemElement.innerHTML = ` | |
<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> | |
`; | |
menuContainer.appendChild(itemElement); | |
}); | |
} | |
} | |
// Function to add an item to the cart | |
function addToCart(itemName, quantity) { | |
cart.push({ name: itemName, price: 250, quantity: quantity }); | |
speak(`${itemName} added to your cart.`); | |
} | |
// 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 handle the order process | |
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.name, 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 find item in the menu | |
function findItem(itemName) { | |
const menu = menuData['Biryanis']; // Default category to check first | |
return menu.find(item => item.name.toLowerCase() === itemName.toLowerCase()); | |
} | |
// Function to populate the menu categories and items | |
window.onload = function() { | |
// Sample menu data for Main Course and Appetizers | |
menuData = { | |
'Main Course': [ | |
{ name: "Chicken Biryani", price: 250 }, | |
{ name: "Veg Biryani", price: 200 }, | |
{ name: "Mutton Biryani", price: 300 } | |
], | |
'Appetizers': [ | |
{ name: "Paneer Tikka", price: 180 }, | |
{ name: "Chicken Wings", price: 220 } | |
] | |
}; | |
// Populate categories dynamically | |
document.getElementById("main-course-btn").addEventListener("click", () => { | |
displayMenuItems('Main Course'); | |
}); | |
document.getElementById("appetizer-btn").addEventListener("click", () => { | |
displayMenuItems('Appetizers'); | |
}); | |
// Voice greeting for menu categories | |
speak("Welcome to Biryani Hub! We have the following categories: Main Course and Appetizers."); | |
}; | |
</script> | |
</body> | |
</html> | |