DSatishchandra commited on
Commit
92deae9
·
verified ·
1 Parent(s): d660836

Update templates/menu_page.html

Browse files
Files changed (1) hide show
  1. templates/menu_page.html +93 -65
templates/menu_page.html CHANGED
@@ -80,78 +80,106 @@
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">
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
- let isListening = false;
101
 
102
- micButton.addEventListener('click', () => {
103
- if (!isListening) {
104
- isListening = true;
105
- greetUser();
106
- }
107
- });
108
-
109
- // Greeting the user and asking for their name
110
- function greetUser() {
111
- const utterance = new SpeechSynthesisUtterance("Hi, welcome to Biryani Hub! Can I know your name so I can greet you personally?");
112
- speechSynthesis.speak(utterance);
113
- utterance.onend = () => {
114
- status.textContent = "Listening for your name...";
115
- startListening();
116
- };
117
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
- // Start listening for the user's response
120
- async function startListening() {
121
- const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
122
- const mediaRecorder = new MediaRecorder(stream, { mimeType: "audio/webm;codecs=opus" });
123
- const audioChunks = [];
124
- mediaRecorder.ondataavailable = (event) => audioChunks.push(event.data);
125
- mediaRecorder.onstop = async () => {
126
- const audioBlob = new Blob(audioChunks, { type: "audio/webm" });
127
- const formData = new FormData();
128
- formData.append("audio", audioBlob);
129
- status.textContent = "Processing your preference... Please wait.";
130
- try {
131
- const result = await fetch("/process-audio", { method: "POST", body: formData });
132
- const data = await result.json();
133
- response.textContent = data.response;
134
- response.style.display = "block";
135
- const utterance = new SpeechSynthesisUtterance(data.response);
136
- speechSynthesis.speak(utterance);
137
- utterance.onend = () => {
138
- if (!data.response.includes("Goodbye") && !data.response.includes("final order")) {
139
- startListening(); // Continue listening
140
- } else {
141
- status.textContent = "Conversation ended.";
142
- isListening = false;
143
- }
144
- };
145
- } catch (error) {
146
- response.textContent = "Sorry, I couldn’t understand that. Could you please repeat?";
147
- status.textContent = "Press the mic button to restart.";
148
- isListening = false;
149
- }
150
- };
151
- mediaRecorder.start();
152
- setTimeout(() => mediaRecorder.stop(), 5000); // Stop recording after 5 seconds
 
 
 
153
  }
154
- </script>
 
 
 
155
 
 
156
  </body>
157
  </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">
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
+
95
  </div>
96
 
97
+ <script>
98
+ const micButton = document.getElementById('mic-button');
99
+ const status = document.getElementById('status');
100
+ const response = document.getElementById('response');
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
+ // Additional example: GET request to fetch some data (e.g., menu items)
168
+ async function fetchMenuItems() {
169
+ try {
170
+ const result = await fetch("/menu"); // This is a GET request
171
+ const menuItems = await result.json();
172
+
173
+ // Process the menu items or display them as needed
174
+ console.log(menuItems); // You can now use this data to display menu items on the page
175
+ } catch (error) {
176
+ console.error("Error fetching menu items:", error);
177
  }
178
+ }
179
+
180
+ // Call fetchMenuItems to load the menu when the page is ready or as needed
181
+ fetchMenuItems();
182
 
183
+ </script>
184
  </body>
185
  </html>