lokesh341 commited on
Commit
4567551
·
verified ·
1 Parent(s): 20ea335

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +30 -35
templates/index.html CHANGED
@@ -76,8 +76,8 @@
76
 
77
  <script>
78
  let recognition;
79
- let currentName = ""; // Variable to store the name as it's being formed
80
- let currentEmail = ""; // Variable to store the email as it's being formed
81
  let isNameCaptured = false;
82
  let isEmailCaptured = false;
83
 
@@ -92,7 +92,7 @@
92
 
93
  function speak(text, callback) {
94
  const speech = new SpeechSynthesisUtterance(text);
95
- speech.onend = callback; // Once the speech ends, call the next function
96
  window.speechSynthesis.speak(speech);
97
  }
98
 
@@ -102,55 +102,50 @@
102
  status.textContent = "Listening for your name...";
103
  recognition.start();
104
  recognition.onresult = function(event) {
105
- const transcript = event.results[0][0].transcript.trim();
106
-
107
- // Capture the individual letter spoken
108
- currentName += transcript; // Append the current letter to the name
109
- nameInput.value = currentName; // Display the updated name input
110
-
111
- // Optionally, speak out the name as it's being typed
112
- speak(transcript, null); // Say the captured letter
113
-
114
- // If the user says "next", stop and move to email
115
- if (transcript.toLowerCase() === "next") {
116
- recognition.stop(); // Stop the recognition for name
117
  isNameCaptured = true;
118
  status.textContent = "Your name is captured. Now listening for your email...";
119
- speak("Now, please tell me your email", startListeningForEmail);
 
120
  }
 
 
 
 
121
  };
122
  }
123
 
124
  function startListeningForEmail() {
125
  const status = document.getElementById('status');
126
  const emailInput = document.getElementById('email');
127
- recognition.stop(); // Stop the previous recognition
128
- recognition = new webkitSpeechRecognition(); // Recreate a new recognition object
129
- recognition.continuous = false; // Reset to stop after capturing each input
 
130
  recognition.interimResults = false;
131
- recognition.lang = 'en-US'; // Reset language
132
 
133
  status.textContent = "Listening for your email...";
134
  recognition.start();
135
  recognition.onresult = function(event) {
136
- const transcript = event.results[0][0].transcript.trim();
137
-
138
- // Capture the individual letter spoken
139
- currentEmail += transcript; // Append the current letter to the email
140
- emailInput.value = currentEmail; // Display the updated email input
141
-
142
- // Optionally, speak out the email as it's being typed
143
- speak(transcript, null); // Say the captured letter
144
-
145
- // If the user says "next", stop and finalize the registration
146
- if (transcript.toLowerCase() === "next") {
147
- recognition.stop(); // Stop the recognition for email
148
  isEmailCaptured = true;
149
  status.textContent = 'Registration complete.';
150
-
151
- // After registration, refresh the page after 20 seconds
152
- setTimeout(() => location.reload(), 20000); // Refresh after 20 seconds
 
153
  }
 
 
 
 
154
  };
155
  }
156
 
 
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 isNameCaptured = false;
82
  let isEmailCaptured = false;
83
 
 
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
  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 === "next") {
108
+ recognition.stop(); // Stop recognition immediately
 
 
 
 
 
 
 
 
109
  isNameCaptured = true;
110
  status.textContent = "Your name is captured. Now listening for your email...";
111
+ speak("Now, please tell me your email, letter by letter", startListeningForEmail);
112
+ return; // Exit function so "next" is not appended to name
113
  }
114
+
115
+ // Append spoken letters to the name
116
+ currentName += transcript + " "; // Space between letters for readability
117
+ nameInput.value = currentName.trim(); // Display the updated name
118
  };
119
  }
120
 
121
  function startListeningForEmail() {
122
  const status = document.getElementById('status');
123
  const emailInput = document.getElementById('email');
124
+ recognition.stop(); // Stop previous recognition
125
+
126
+ recognition = new webkitSpeechRecognition(); // Reset recognition
127
+ recognition.continuous = false;
128
  recognition.interimResults = false;
129
+ recognition.lang = 'en-US';
130
 
131
  status.textContent = "Listening for your email...";
132
  recognition.start();
133
  recognition.onresult = function(event) {
134
+ const transcript = event.results[0][0].transcript.trim().toLowerCase();
135
+
136
+ if (transcript === "next") {
137
+ recognition.stop(); // Stop recognition for email
 
 
 
 
 
 
 
 
138
  isEmailCaptured = true;
139
  status.textContent = 'Registration complete.';
140
+ speak("Registration complete. Thank you!", function() {
141
+ setTimeout(() => location.reload(), 10000); // Refresh after 10 sec
142
+ });
143
+ return; // Exit function to prevent "next" from being added
144
  }
145
+
146
+ // Append spoken letters to the email
147
+ currentEmail += transcript;
148
+ emailInput.value = currentEmail.trim();
149
  };
150
  }
151