Spaces:
Sleeping
Sleeping
Update templates/menu_page.html
Browse files- templates/menu_page.html +104 -33
templates/menu_page.html
CHANGED
|
@@ -91,48 +91,119 @@
|
|
| 91 |
</div>
|
| 92 |
|
| 93 |
<script>
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
}
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
});
|
| 109 |
-
|
|
|
|
| 110 |
recognition.onresult = (event) => {
|
| 111 |
-
const
|
| 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 |
</body>
|
| 138 |
</html>
|
|
|
|
| 91 |
</div>
|
| 92 |
|
| 93 |
<script>
|
| 94 |
+
const listenButton = document.getElementById("listen-btn");
|
| 95 |
+
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
| 96 |
+
recognition.lang = "en-US";
|
| 97 |
+
recognition.interimResults = false;
|
| 98 |
+
|
| 99 |
+
let cart = []; // To store the cart items
|
| 100 |
+
|
| 101 |
+
function speak(text) {
|
| 102 |
+
const msg = new SpeechSynthesisUtterance(text);
|
| 103 |
+
window.speechSynthesis.speak(msg);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
listenButton.addEventListener("click", () => {
|
| 107 |
+
speak("Please say the category you want to explore, such as Appetizer or Main Course.");
|
| 108 |
+
recognition.start();
|
| 109 |
+
});
|
| 110 |
+
|
| 111 |
+
recognition.onresult = (event) => {
|
| 112 |
+
const command = event.results[0][0].transcript.toLowerCase();
|
| 113 |
+
console.log("User said:", command);
|
| 114 |
+
|
| 115 |
+
if (command.includes("appetizer") || command.includes("main course")) {
|
| 116 |
+
// Identify the category and filter items (for demo, we simply proceed with a generic response)
|
| 117 |
+
const category = command.includes("appetizer") ? "Appetizer" : "Main Course";
|
| 118 |
+
speak(`You selected ${category}. What would you like to order from the ${category} menu?`);
|
| 119 |
+
askForItem(category);
|
| 120 |
+
} else {
|
| 121 |
+
speak("Sorry, I couldn't recognize that. Please say 'Appetizer' or 'Main Course'.");
|
| 122 |
}
|
| 123 |
+
};
|
| 124 |
+
|
| 125 |
+
function askForItem(category) {
|
| 126 |
+
// Get all items from the selected category
|
| 127 |
+
const items = document.querySelectorAll(`.menu-item[data-category="${category}"]`);
|
| 128 |
+
let itemsText = `The ${category} menu includes: `;
|
| 129 |
+
items.forEach(item => {
|
| 130 |
+
itemsText += item.querySelector("h3").textContent + ", ";
|
| 131 |
});
|
| 132 |
+
speak(itemsText);
|
| 133 |
+
recognition.start();
|
| 134 |
recognition.onresult = (event) => {
|
| 135 |
+
const itemOrdered = event.results[0][0].transcript.toLowerCase();
|
| 136 |
+
const itemElement = Array.from(items).find(item => item.querySelector("h3").textContent.toLowerCase().includes(itemOrdered));
|
| 137 |
+
|
| 138 |
+
if (itemElement) {
|
| 139 |
+
const itemName = itemElement.querySelector("h3").textContent;
|
| 140 |
+
speak(`You selected ${itemName}. How many would you like to order?`);
|
| 141 |
+
askForQuantity(itemName);
|
| 142 |
+
} else {
|
| 143 |
+
speak("Sorry, I couldn't find that item. Please say the item again.");
|
| 144 |
+
}
|
| 145 |
+
};
|
| 146 |
+
}
|
| 147 |
|
| 148 |
+
function askForQuantity(itemName) {
|
| 149 |
+
recognition.start();
|
| 150 |
+
recognition.onresult = (event) => {
|
| 151 |
+
const quantity = event.results[0][0].transcript.trim();
|
| 152 |
+
if (isNaN(quantity)) {
|
| 153 |
+
speak("Sorry, I didn't catch that. Please say a number.");
|
| 154 |
+
} else {
|
| 155 |
+
cart.push({ itemName, quantity });
|
| 156 |
+
speak(`${quantity} of ${itemName} added to your cart. Would you like to add more items?`);
|
| 157 |
+
askToContinue();
|
| 158 |
}
|
| 159 |
};
|
| 160 |
+
}
|
| 161 |
|
| 162 |
+
function askToContinue() {
|
| 163 |
+
recognition.start();
|
| 164 |
+
recognition.onresult = (event) => {
|
| 165 |
+
const command = event.results[0][0].transcript.toLowerCase();
|
| 166 |
+
if (command.includes("yes")) {
|
| 167 |
+
speak("What would you like to order next?");
|
| 168 |
+
recognition.stop();
|
| 169 |
+
} else if (command.includes("no")) {
|
| 170 |
+
announceCartSummary();
|
| 171 |
+
} else {
|
| 172 |
+
speak("Sorry, I didn't understand. Please say 'yes' to continue or 'no' to proceed to checkout.");
|
| 173 |
+
}
|
| 174 |
};
|
| 175 |
+
}
|
| 176 |
|
| 177 |
+
function announceCartSummary() {
|
| 178 |
+
let cartSummary = "Your cart includes: ";
|
| 179 |
+
cart.forEach(item => {
|
| 180 |
+
cartSummary += `${item.quantity} of ${item.itemName}, `;
|
| 181 |
+
});
|
| 182 |
+
cartSummary += "Would you like to proceed with the order?";
|
| 183 |
+
speak(cartSummary);
|
| 184 |
+
confirmationForOrder();
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
function confirmationForOrder() {
|
| 188 |
+
recognition.start();
|
| 189 |
+
recognition.onresult = (event) => {
|
| 190 |
+
const confirmation = event.results[0][0].transcript.toLowerCase();
|
| 191 |
+
if (confirmation.includes("yes")) {
|
| 192 |
+
speak("Your order has been placed successfully. Thank you!");
|
| 193 |
+
// Implement the final order placing logic here
|
| 194 |
+
} else if (confirmation.includes("no")) {
|
| 195 |
+
speak("Your order has been cancelled. Thank you!");
|
| 196 |
+
// Cancel order logic
|
| 197 |
+
} else {
|
| 198 |
+
speak("Sorry, I didn't understand. Please confirm if you'd like to place the order.");
|
| 199 |
+
}
|
| 200 |
+
};
|
| 201 |
+
}
|
| 202 |
|
| 203 |
+
recognition.onerror = (event) => {
|
| 204 |
+
console.error("Speech recognition error:", event.error);
|
| 205 |
+
speak("Sorry, I couldn't understand that. Please try again.");
|
| 206 |
+
};
|
| 207 |
+
</script>
|
| 208 |
</body>
|
| 209 |
</html>
|