Spaces:
Sleeping
Sleeping
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Menu - Biryani Hub</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 { | |
display: none; /* Hide the button since ordering is voice-controlled */ | |
} | |
</style> | |
</head> | |
<body> | |
<div class="menu-container"> | |
<h1>Welcome to the Menu</h1> | |
{% for item in menu_items %} | |
<div class="menu-item" data-item="{{ item.name | lower }}"> | |
<div class="details"> | |
<h3>{{ item.name }}</h3> | |
<p><strong>Ingredients:</strong> {{ item.ingredients }}</p> | |
<p><strong>Category:</strong> {{ item.category }}</p> | |
<p class="price">Price: ${{ item.price }}</p> | |
</div> | |
<button class="order-btn">Order</button> | |
</div> | |
{% endfor %} | |
</div> | |
<script> | |
const menuItems = Array.from(document.querySelectorAll(".menu-item")).map(item => ({ | |
name: item.dataset.item, | |
element: item | |
})); | |
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)(); | |
recognition.lang = "en-US"; | |
recognition.interimResults = false; | |
function speak(text, callback) { | |
const msg = new SpeechSynthesisUtterance(text); | |
msg.onend = callback; | |
window.speechSynthesis.speak(msg); | |
} | |
function readMenuItems() { | |
let menuText = "Here is the menu. "; | |
menuItems.forEach(item => { | |
menuText += `${item.name}. `; | |
}); | |
menuText += "Please say the name of the item you would like to order."; | |
speak(menuText, startListening); | |
} | |
function startListening() { | |
recognition.start(); | |
} | |
recognition.onresult = (event) => { | |
const command = event.results[0][0].transcript.toLowerCase(); | |
console.log("User said:", command); | |
const matchedItem = menuItems.find(item => command.includes(item.name)); | |
if (matchedItem) { | |
speak(`You have ordered ${matchedItem.name}. Your order has been placed.`); | |
console.log(`Order placed for: ${matchedItem.name}`); | |
} else { | |
speak("Item not found. Please try again."); | |
startListening(); | |
} | |
}; | |
recognition.onerror = (event) => { | |
console.error("Speech recognition error:", event.error); | |
speak("Sorry, I couldn't understand that. Please try again."); | |
}; | |
// Automatically read the menu and start listening when the page loads | |
window.onload = function () { | |
readMenuItems(); | |
}; | |
</script> | |
</body> | |
</html> | |