Update templates/menu_page.html
Browse files- templates/menu_page.html +64 -17
templates/menu_page.html
CHANGED
|
@@ -74,36 +74,44 @@
|
|
| 74 |
<div class="menu-container">
|
| 75 |
<h1>Welcome to the Menu</h1>
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
</div>
|
| 85 |
-
<button class="order-btn">Order</button>
|
| 86 |
</div>
|
| 87 |
-
{% endfor %}
|
| 88 |
|
| 89 |
<!-- Button for triggering voice recognition -->
|
| 90 |
-
<button id="listen-btn">Say "
|
| 91 |
</div>
|
| 92 |
|
| 93 |
<script>
|
| 94 |
const listenButton = document.getElementById("listen-btn");
|
| 95 |
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
| 96 |
-
|
| 97 |
recognition.lang = "en-US";
|
| 98 |
recognition.interimResults = false;
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
function speak(text) {
|
| 101 |
const msg = new SpeechSynthesisUtterance(text);
|
| 102 |
window.speechSynthesis.speak(msg);
|
| 103 |
}
|
| 104 |
|
| 105 |
listenButton.addEventListener("click", () => {
|
| 106 |
-
speak("Please say
|
| 107 |
recognition.start();
|
| 108 |
});
|
| 109 |
|
|
@@ -111,10 +119,12 @@
|
|
| 111 |
const command = event.results[0][0].transcript.toLowerCase();
|
| 112 |
console.log("User said:", command);
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
| 118 |
}
|
| 119 |
};
|
| 120 |
|
|
@@ -122,6 +132,43 @@
|
|
| 122 |
console.error("Speech recognition error:", event.error);
|
| 123 |
speak("Sorry, I couldn't understand that. Please try again.");
|
| 124 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
</script>
|
| 126 |
|
| 127 |
</body>
|
|
|
|
| 74 |
<div class="menu-container">
|
| 75 |
<h1>Welcome to the Menu</h1>
|
| 76 |
|
| 77 |
+
<div id="category-selection">
|
| 78 |
+
<h2>Please say a category: "Appetizer" or "Main Course"</h2>
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
<div id="menu-items-container" style="display:none;">
|
| 82 |
+
<h2>Menu Items</h2>
|
| 83 |
+
<div id="menu-items"></div>
|
|
|
|
|
|
|
| 84 |
</div>
|
|
|
|
| 85 |
|
| 86 |
<!-- Button for triggering voice recognition -->
|
| 87 |
+
<button id="listen-btn">Say "Appetizer" or "Main Course"</button>
|
| 88 |
</div>
|
| 89 |
|
| 90 |
<script>
|
| 91 |
const listenButton = document.getElementById("listen-btn");
|
| 92 |
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
|
|
|
| 93 |
recognition.lang = "en-US";
|
| 94 |
recognition.interimResults = false;
|
| 95 |
|
| 96 |
+
// Sample menu items data (you can dynamically fetch this from a backend if needed)
|
| 97 |
+
const menuData = {
|
| 98 |
+
"Appetizer": [
|
| 99 |
+
{ "name": "Spring Rolls", "price": "$5.99", "ingredients": "Rice Paper, Shrimp, Lettuce" },
|
| 100 |
+
{ "name": "Chicken Wings", "price": "$7.99", "ingredients": "Chicken, Spices, Garlic" },
|
| 101 |
+
],
|
| 102 |
+
"Main Course": [
|
| 103 |
+
{ "name": "Biryani", "price": "$12.99", "ingredients": "Rice, Chicken, Spices" },
|
| 104 |
+
{ "name": "Paneer Butter Masala", "price": "$10.99", "ingredients": "Paneer, Butter, Cream" },
|
| 105 |
+
]
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
function speak(text) {
|
| 109 |
const msg = new SpeechSynthesisUtterance(text);
|
| 110 |
window.speechSynthesis.speak(msg);
|
| 111 |
}
|
| 112 |
|
| 113 |
listenButton.addEventListener("click", () => {
|
| 114 |
+
speak("Please say 'Appetizer' or 'Main Course'.");
|
| 115 |
recognition.start();
|
| 116 |
});
|
| 117 |
|
|
|
|
| 119 |
const command = event.results[0][0].transcript.toLowerCase();
|
| 120 |
console.log("User said:", command);
|
| 121 |
|
| 122 |
+
if (command.includes("appetizer") || command.includes("main course")) {
|
| 123 |
+
// Handle recognized category
|
| 124 |
+
handleCategorySelection(command);
|
| 125 |
+
} else {
|
| 126 |
+
speak("Sorry, I didn't understand. Please say 'Appetizer' or 'Main Course'.");
|
| 127 |
+
recognition.start(); // Restart recognition if invalid category
|
| 128 |
}
|
| 129 |
};
|
| 130 |
|
|
|
|
| 132 |
console.error("Speech recognition error:", event.error);
|
| 133 |
speak("Sorry, I couldn't understand that. Please try again.");
|
| 134 |
};
|
| 135 |
+
|
| 136 |
+
function handleCategorySelection(category) {
|
| 137 |
+
const categoryName = category.includes("appetizer") ? "Appetizer" : "Main Course";
|
| 138 |
+
const items = menuData[categoryName];
|
| 139 |
+
|
| 140 |
+
document.getElementById("category-selection").style.display = "none"; // Hide category prompt
|
| 141 |
+
document.getElementById("menu-items-container").style.display = "block"; // Show menu items
|
| 142 |
+
|
| 143 |
+
// Display menu items for the selected category
|
| 144 |
+
const menuItemsContainer = document.getElementById("menu-items");
|
| 145 |
+
menuItemsContainer.innerHTML = ""; // Clear existing items
|
| 146 |
+
items.forEach(item => {
|
| 147 |
+
const itemElement = document.createElement("div");
|
| 148 |
+
itemElement.classList.add("menu-item");
|
| 149 |
+
itemElement.innerHTML = `
|
| 150 |
+
<div class="details">
|
| 151 |
+
<h3>${item.name}</h3>
|
| 152 |
+
<p><strong>Ingredients:</strong> ${item.ingredients}</p>
|
| 153 |
+
<p class="price">Price: ${item.price}</p>
|
| 154 |
+
</div>
|
| 155 |
+
<button class="order-btn">Order</button>
|
| 156 |
+
`;
|
| 157 |
+
menuItemsContainer.appendChild(itemElement);
|
| 158 |
+
});
|
| 159 |
+
|
| 160 |
+
// Read out the list of items
|
| 161 |
+
let itemsText = `The following items are available in the ${categoryName}: `;
|
| 162 |
+
items.forEach(item => {
|
| 163 |
+
itemsText += item.name + ", ";
|
| 164 |
+
});
|
| 165 |
+
speak(itemsText); // Speak the items
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
window.onload = function() {
|
| 169 |
+
// Initial page load will prompt for category selection
|
| 170 |
+
speak("Welcome to the Menu. Please say 'Appetizer' or 'Main Course'.");
|
| 171 |
+
};
|
| 172 |
</script>
|
| 173 |
|
| 174 |
</body>
|