lokesh341 commited on
Commit
7004432
·
verified ·
1 Parent(s): 93f26a2

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +51 -44
templates/index.html CHANGED
@@ -41,6 +41,7 @@
41
  border: 1px solid #ccc;
42
  border-radius: 5px;
43
  margin-top: 8px;
 
44
  }
45
  .info {
46
  margin-top: 20px;
@@ -76,14 +77,14 @@
76
 
77
  <script>
78
  let recognition;
79
- let currentName = ""; // Store the name as it's being formed
80
- let currentEmail = ""; // Store the email as it's being formed
81
  let isCapturingName = true;
82
  let isCapturingEmail = false;
83
 
84
  if ('webkitSpeechRecognition' in window) {
85
  recognition = new webkitSpeechRecognition();
86
- recognition.continuous = false; // Stop after capturing each input
87
  recognition.interimResults = false;
88
  recognition.lang = 'en-US';
89
  } else {
@@ -92,7 +93,7 @@
92
 
93
  function speak(text, callback) {
94
  const speech = new SpeechSynthesisUtterance(text);
95
- speech.onend = callback; // Call the next function after speech ends
96
  window.speechSynthesis.speak(speech);
97
  }
98
 
@@ -102,31 +103,33 @@
102
  status.textContent = "Listening for your name...";
103
  recognition.start();
104
  recognition.onresult = function(event) {
105
- const transcript = event.results[0][0].transcript.trim().toLowerCase();
106
 
107
- if (transcript.includes("next")) {
108
- recognition.stop(); // Stop recognition immediately
109
  isCapturingName = false;
110
  isCapturingEmail = true;
111
- status.textContent = "Your name is captured. Now listening for your email...";
112
 
113
- // Ensure name input is finalized
114
- nameInput.value = currentName.trim();
115
-
116
- speak("Now, please tell me your email, letter by letter", function() {
117
- startListeningForEmail(); // Start email capture
 
 
 
 
 
 
 
118
  });
119
 
120
- return; // Exit function to prevent "next" from being added to the name
121
  }
122
 
123
- // Append spoken letters to the name
124
- currentName += transcript + " "; // Space between letters for readability
125
- nameInput.value = currentName.trim(); // Display the updated name
126
- };
127
-
128
- recognition.onspeechend = function() {
129
- recognition.stop(); // Stop after input ends
130
  };
131
  }
132
 
@@ -134,7 +137,6 @@
134
  const status = document.getElementById('status');
135
  const emailInput = document.getElementById('email');
136
 
137
- // Reset recognition for email input
138
  recognition = new webkitSpeechRecognition();
139
  recognition.continuous = false;
140
  recognition.interimResults = false;
@@ -143,43 +145,48 @@
143
  status.textContent = "Listening for your email...";
144
  recognition.start();
145
  recognition.onresult = function(event) {
146
- const transcript = event.results[0][0].transcript.trim().toLowerCase();
 
 
 
147
 
148
- if (transcript.includes("next")) {
149
- recognition.stop(); // Stop recognition for email
150
  isCapturingEmail = false;
151
- status.textContent = 'Registration complete.';
152
-
153
- // Ensure email input is finalized
154
- emailInput.value = currentEmail.trim();
155
-
156
- speak("Registration complete. Thank you!", function() {
157
- setTimeout(() => location.reload(), 10000); // Refresh after 10 sec
 
 
 
 
 
 
 
 
 
158
  });
159
 
160
- return; // Exit function to prevent "next" from being added
161
  }
162
 
163
- // Append spoken letters to the email
164
- currentEmail += transcript + " ";
165
- emailInput.value = currentEmail.trim();
166
- };
167
-
168
- recognition.onspeechend = function() {
169
- recognition.stop(); // Stop after input ends
170
  };
171
  }
172
 
173
  function startProcess() {
174
  speak("Welcome to Biryani Hub", function() {
175
- speak("Tell me your name, letter by letter, and say 'next' when you're done", function() {
176
- startListeningForName();
177
- });
178
  });
179
  }
180
 
181
  window.onload = function () {
182
- setTimeout(startProcess, 4000); // Start process after 4 seconds
183
  };
184
  </script>
185
  </body>
 
41
  border: 1px solid #ccc;
42
  border-radius: 5px;
43
  margin-top: 8px;
44
+ text-transform: uppercase;
45
  }
46
  .info {
47
  margin-top: 20px;
 
77
 
78
  <script>
79
  let recognition;
80
+ let currentName = "";
81
+ let currentEmail = "";
82
  let isCapturingName = true;
83
  let isCapturingEmail = false;
84
 
85
  if ('webkitSpeechRecognition' in window) {
86
  recognition = new webkitSpeechRecognition();
87
+ recognition.continuous = false;
88
  recognition.interimResults = false;
89
  recognition.lang = 'en-US';
90
  } else {
 
93
 
94
  function speak(text, callback) {
95
  const speech = new SpeechSynthesisUtterance(text);
96
+ speech.onend = callback;
97
  window.speechSynthesis.speak(speech);
98
  }
99
 
 
103
  status.textContent = "Listening for your name...";
104
  recognition.start();
105
  recognition.onresult = function(event) {
106
+ let transcript = event.results[0][0].transcript.trim().toUpperCase().replace(/\s+/g, "");
107
 
108
+ if (transcript === "NEXT") {
109
+ recognition.stop();
110
  isCapturingName = false;
111
  isCapturingEmail = true;
112
+ status.textContent = "Your name is: " + currentName;
113
 
114
+ speak("Your name is " + currentName + ". If correct, say 'confirm'. If wrong, say 'edit'.", function() {
115
+ recognition.start();
116
+ recognition.onresult = function(event) {
117
+ let confirmTranscript = event.results[0][0].transcript.trim().toLowerCase();
118
+ if (confirmTranscript === "confirm") {
119
+ speak("Now, please tell me your email, letter by letter", startListeningForEmail);
120
+ } else if (confirmTranscript === "edit") {
121
+ currentName = "";
122
+ nameInput.value = "";
123
+ speak("Tell your name again.", startListeningForName);
124
+ }
125
+ };
126
  });
127
 
128
+ return;
129
  }
130
 
131
+ currentName += transcript;
132
+ nameInput.value = currentName;
 
 
 
 
 
133
  };
134
  }
135
 
 
137
  const status = document.getElementById('status');
138
  const emailInput = document.getElementById('email');
139
 
 
140
  recognition = new webkitSpeechRecognition();
141
  recognition.continuous = false;
142
  recognition.interimResults = false;
 
145
  status.textContent = "Listening for your email...";
146
  recognition.start();
147
  recognition.onresult = function(event) {
148
+ let transcript = event.results[0][0].transcript.trim().toUpperCase().replace(/\s+/g, "");
149
+
150
+ // Replace "AT" with "@", "DOT" with "."
151
+ transcript = transcript.replace(/\bAT\b/g, "@").replace(/\bDOT\b/g, ".");
152
 
153
+ if (transcript === "NEXT") {
154
+ recognition.stop();
155
  isCapturingEmail = false;
156
+ status.textContent = "Your email is: " + currentEmail;
157
+
158
+ speak("Your email is " + currentEmail + ". If correct, say 'confirm'. If wrong, say 'edit'.", function() {
159
+ recognition.start();
160
+ recognition.onresult = function(event) {
161
+ let confirmTranscript = event.results[0][0].transcript.trim().toLowerCase();
162
+ if (confirmTranscript === "confirm") {
163
+ speak("Registration complete. Thank you!", function() {
164
+ setTimeout(() => location.reload(), 10000);
165
+ });
166
+ } else if (confirmTranscript === "edit") {
167
+ currentEmail = "";
168
+ emailInput.value = "";
169
+ speak("Tell your email again.", startListeningForEmail);
170
+ }
171
+ };
172
  });
173
 
174
+ return;
175
  }
176
 
177
+ currentEmail += transcript;
178
+ emailInput.value = currentEmail;
 
 
 
 
 
179
  };
180
  }
181
 
182
  function startProcess() {
183
  speak("Welcome to Biryani Hub", function() {
184
+ speak("Tell me your name, letter by letter, and say 'next' when you're done", startListeningForName);
 
 
185
  });
186
  }
187
 
188
  window.onload = function () {
189
+ setTimeout(startProcess, 4000);
190
  };
191
  </script>
192
  </body>