Spaces:
Sleeping
Sleeping
Update templates/menu_page.html
Browse files- templates/menu_page.html +98 -92
templates/menu_page.html
CHANGED
|
@@ -80,106 +80,112 @@
|
|
| 80 |
<div class="response" id="response">Response will appear here...</div>
|
| 81 |
|
| 82 |
<!-- Display the menu items dynamically -->
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
| 91 |
</div>
|
| 92 |
-
{% endfor %}
|
| 93 |
-
</div>
|
| 94 |
-
|
| 95 |
</div>
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
isListening
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
});
|
| 109 |
-
|
| 110 |
-
// Greeting the user and asking for their name
|
| 111 |
-
function greetUser() {
|
| 112 |
-
const utterance = new SpeechSynthesisUtterance("Hi, welcome to Biryani Hub! Can I know your name so I can greet you personally?");
|
| 113 |
-
speechSynthesis.speak(utterance);
|
| 114 |
-
utterance.onend = () => {
|
| 115 |
-
status.textContent = "Listening for your name...";
|
| 116 |
-
startListening();
|
| 117 |
-
};
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
// Start listening for the user's response
|
| 121 |
-
async function startListening() {
|
| 122 |
-
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 123 |
-
const mediaRecorder = new MediaRecorder(stream, { mimeType: "audio/webm;codecs=opus" });
|
| 124 |
-
const audioChunks = [];
|
| 125 |
-
mediaRecorder.ondataavailable = (event) => audioChunks.push(event.data);
|
| 126 |
-
mediaRecorder.onstop = async () => {
|
| 127 |
-
const audioBlob = new Blob(audioChunks, { type: "audio/webm" });
|
| 128 |
-
const formData = new FormData();
|
| 129 |
-
formData.append("audio", audioBlob);
|
| 130 |
-
|
| 131 |
-
status.textContent = "Processing your preference... Please wait.";
|
| 132 |
-
|
| 133 |
-
try {
|
| 134 |
-
// POST request to send the recorded audio to the server for processing
|
| 135 |
-
const result = await fetch("/process-audio", {
|
| 136 |
-
method: "POST",
|
| 137 |
-
body: formData
|
| 138 |
-
});
|
| 139 |
-
|
| 140 |
-
const data = await result.json(); // Get the server's response
|
| 141 |
-
|
| 142 |
-
// Display the response and use speech synthesis to speak the response
|
| 143 |
-
response.textContent = data.response;
|
| 144 |
-
response.style.display = "block";
|
| 145 |
-
const utterance = new SpeechSynthesisUtterance(data.response);
|
| 146 |
-
speechSynthesis.speak(utterance);
|
| 147 |
-
|
| 148 |
-
utterance.onend = () => {
|
| 149 |
-
// Handle further interaction or end conversation
|
| 150 |
-
if (!data.response.includes("Goodbye") && !data.response.includes("final order")) {
|
| 151 |
-
startListening(); // Continue listening
|
| 152 |
-
} else {
|
| 153 |
-
status.textContent = "Conversation ended.";
|
| 154 |
-
isListening = false;
|
| 155 |
-
}
|
| 156 |
-
};
|
| 157 |
-
} catch (error) {
|
| 158 |
-
response.textContent = "Sorry, I couldn’t understand that. Could you please repeat?";
|
| 159 |
-
status.textContent = "Press the mic button to restart.";
|
| 160 |
-
isListening = false;
|
| 161 |
}
|
| 162 |
-
};
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
const
|
| 171 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
}
|
| 178 |
-
}
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
-
</script>
|
| 184 |
</body>
|
| 185 |
</html>
|
|
|
|
| 80 |
<div class="response" id="response">Response will appear here...</div>
|
| 81 |
|
| 82 |
<!-- Display the menu items dynamically -->
|
| 83 |
+
<div class="menu-items-container">
|
| 84 |
+
{% for item in menu_items %}
|
| 85 |
+
<div class="menu-item" id="menu-item-{{ loop.index }}">
|
| 86 |
+
<h3>{{ item.Name }}</h3>
|
| 87 |
+
<p><strong>Price:</strong> ${{ item.Price__c }}</p>
|
| 88 |
+
<p><strong>Ingredients:</strong> {{ item.Ingredients__c }}</p>
|
| 89 |
+
<p><strong>Category:</strong> {{ item.Category__c }}</p>
|
| 90 |
+
<button class="order-btn" data-item="{{ item.Name }}">Order</button>
|
| 91 |
+
</div>
|
| 92 |
+
{% endfor %}
|
| 93 |
</div>
|
|
|
|
|
|
|
|
|
|
| 94 |
</div>
|
| 95 |
|
| 96 |
+
<script>
|
| 97 |
+
const micButton = document.getElementById('mic-button');
|
| 98 |
+
const status = document.getElementById('status');
|
| 99 |
+
const response = document.getElementById('response');
|
| 100 |
+
const menuItemsContainer = document.querySelector('.menu-items-container');
|
| 101 |
+
let isListening = false;
|
| 102 |
+
|
| 103 |
+
micButton.addEventListener('click', () => {
|
| 104 |
+
if (!isListening) {
|
| 105 |
+
isListening = true;
|
| 106 |
+
greetUser();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
}
|
| 108 |
+
});
|
| 109 |
+
|
| 110 |
+
// Greeting the user and asking for their name
|
| 111 |
+
function greetUser() {
|
| 112 |
+
const utterance = new SpeechSynthesisUtterance("Hi, welcome to Biryani Hub! Can I know your name so I can greet you personally?");
|
| 113 |
+
speechSynthesis.speak(utterance);
|
| 114 |
+
utterance.onend = () => {
|
| 115 |
+
status.textContent = "Listening for your name...";
|
| 116 |
+
startListening();
|
| 117 |
+
};
|
| 118 |
+
}
|
| 119 |
|
| 120 |
+
// Start listening for the user's response
|
| 121 |
+
async function startListening() {
|
| 122 |
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 123 |
+
const mediaRecorder = new MediaRecorder(stream, { mimeType: "audio/webm;codecs=opus" });
|
| 124 |
+
const audioChunks = [];
|
| 125 |
+
mediaRecorder.ondataavailable = (event) => audioChunks.push(event.data);
|
| 126 |
+
mediaRecorder.onstop = async () => {
|
| 127 |
+
const audioBlob = new Blob(audioChunks, { type: "audio/webm" });
|
| 128 |
+
const formData = new FormData();
|
| 129 |
+
formData.append("audio", audioBlob);
|
| 130 |
+
|
| 131 |
+
status.textContent = "Processing your preference... Please wait.";
|
| 132 |
+
|
| 133 |
+
try {
|
| 134 |
+
// POST request to send the recorded audio to the server for processing
|
| 135 |
+
const result = await fetch("/process-audio", {
|
| 136 |
+
method: "POST",
|
| 137 |
+
body: formData
|
| 138 |
+
});
|
| 139 |
+
|
| 140 |
+
const data = await result.json(); // Get the server's response
|
| 141 |
+
|
| 142 |
+
// Display the response and use speech synthesis to speak the response
|
| 143 |
+
response.textContent = data.response;
|
| 144 |
+
response.style.display = "block";
|
| 145 |
+
const utterance = new SpeechSynthesisUtterance(data.response);
|
| 146 |
+
speechSynthesis.speak(utterance);
|
| 147 |
+
|
| 148 |
+
utterance.onend = () => {
|
| 149 |
+
// Handle further interaction or end conversation
|
| 150 |
+
if (!data.response.includes("Goodbye") && !data.response.includes("final order")) {
|
| 151 |
+
startListening(); // Continue listening
|
| 152 |
+
} else {
|
| 153 |
+
status.textContent = "Conversation ended.";
|
| 154 |
+
isListening = false;
|
| 155 |
+
}
|
| 156 |
+
};
|
| 157 |
+
} catch (error) {
|
| 158 |
+
response.textContent = "Sorry, I couldn’t understand that. Could you please repeat?";
|
| 159 |
+
status.textContent = "Press the mic button to restart.";
|
| 160 |
+
isListening = false;
|
| 161 |
+
}
|
| 162 |
+
};
|
| 163 |
+
mediaRecorder.start();
|
| 164 |
+
setTimeout(() => mediaRecorder.stop(), 5000); // Stop recording after 5 seconds
|
| 165 |
+
}
|
| 166 |
|
| 167 |
+
// Function to speak out the menu items
|
| 168 |
+
function speakMenuItems() {
|
| 169 |
+
const utterance = new SpeechSynthesisUtterance("Here are the menu items:");
|
| 170 |
+
speechSynthesis.speak(utterance);
|
| 171 |
+
|
| 172 |
+
menuItemsContainer.querySelectorAll('.menu-item').forEach(item => {
|
| 173 |
+
const name = item.querySelector('h3').innerText;
|
| 174 |
+
const price = item.querySelector('p').innerText;
|
| 175 |
+
const ingredients = item.querySelector('p').innerText;
|
| 176 |
+
const category = item.querySelector('p').innerText;
|
| 177 |
+
|
| 178 |
+
const menuItemText = `${name}, Price: ${price}, Ingredients: ${ingredients}, Category: ${category}`;
|
| 179 |
+
const itemUtterance = new SpeechSynthesisUtterance(menuItemText);
|
| 180 |
+
speechSynthesis.speak(itemUtterance);
|
| 181 |
+
});
|
| 182 |
}
|
|
|
|
| 183 |
|
| 184 |
+
// Trigger the speech for menu items when the page loads
|
| 185 |
+
window.onload = function() {
|
| 186 |
+
speakMenuItems();
|
| 187 |
+
};
|
| 188 |
+
</script>
|
| 189 |
|
|
|
|
| 190 |
</body>
|
| 191 |
</html>
|