voicemenu143 / templates /menu_page.html
lokesh341's picture
Update templates/menu_page.html
be7f320 verified
raw
history blame
8.73 kB
<!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; /* Default green color */
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.order-btn:hover {
background-color: #45a049;
}
/* New styles for the category buttons */
#main-course-btn, #appetizer-btn {
padding: 10px 20px;
background-color: orange; /* Change button color to orange */
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1.2rem;
margin: 10px 0;
}
#main-course-btn:hover, #appetizer-btn:hover {
background-color: #FF7F00; /* Darker orange for hover effect */
}
#cart-summary {
display: none;
}
</style>
<div class="menu-container">
<h1>Welcome to Biryani Hub menu</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>
<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 cartSummary = document.getElementById("cart-summary");
const cartDetails = document.getElementById("cart-details");
const categoryButtons = document.getElementById("category-buttons");
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);
}
// Start voice recognition automatically on page load
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. Please say 'Main Course' or 'Appetizers' to select a category.");
// Automatically trigger voice recognition for category selection
recognition.start();
recognition.onresult = (event) => {
const categoryCommand = event.results[0][0].transcript.toLowerCase();
if (categoryCommand.includes("main course")) {
displayMenuItems('Main Course');
} else if (categoryCommand.includes("appetizers")) {
displayMenuItems('Appetizers');
} else {
speak("Sorry, I couldn't understand that. Please say 'Main Course' or 'Appetizers'.");
}
};
};
// 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);
});
// Automatically prompt the user to order
speak("Here are the items in the selected category. Please say the item you want 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 add an item to the cart
function addToCart(itemName, quantity) {
const item = findItem(itemName);
cart.push({ name: item.name, price: item.price, quantity: quantity });
}
// 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 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")) {
recognition.start();
} else {
showCartDetails();
}
};
}
// Function to find item in the menu
function findItem(itemName) {
const menu = menuData['Main Course']; // Default category to check first
return menu.find(item => item.name.toLowerCase() === itemName.toLowerCase());
}
</script>
</body>
</html>