Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +46 -1
templates/index.html
CHANGED
@@ -92,6 +92,7 @@
|
|
92 |
<script>
|
93 |
let recognition;
|
94 |
let isListening = false;
|
|
|
95 |
// Initialize speech recognition
|
96 |
if ('webkitSpeechRecognition' in window) {
|
97 |
recognition = new webkitSpeechRecognition();
|
@@ -111,4 +112,48 @@
|
|
111 |
|
112 |
// Make sure to start listening as soon as the page loads
|
113 |
window.onload = function () {
|
114 |
-
welcomeMessage(); // Automatically say the welcome
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
<script>
|
93 |
let recognition;
|
94 |
let isListening = false;
|
95 |
+
|
96 |
// Initialize speech recognition
|
97 |
if ('webkitSpeechRecognition' in window) {
|
98 |
recognition = new webkitSpeechRecognition();
|
|
|
112 |
|
113 |
// Make sure to start listening as soon as the page loads
|
114 |
window.onload = function () {
|
115 |
+
welcomeMessage(); // Automatically say the welcome message
|
116 |
+
setTimeout(startListening, 5000); // Start listening after the welcome message
|
117 |
+
};
|
118 |
+
|
119 |
+
// Function to start listening to voice input
|
120 |
+
function startListening() {
|
121 |
+
const status = document.getElementById('status');
|
122 |
+
const nameInput = document.getElementById('name');
|
123 |
+
const emailInput = document.getElementById('email');
|
124 |
+
|
125 |
+
status.textContent = 'Listening for your name...';
|
126 |
+
recognition.start(); // Start voice recognition
|
127 |
+
|
128 |
+
// Handle recognition results
|
129 |
+
recognition.onresult = function(event) {
|
130 |
+
const transcript = event.results[event.resultIndex][0].transcript.trim();
|
131 |
+
if (event.results[event.resultIndex].isFinal) {
|
132 |
+
if (!nameInput.value) {
|
133 |
+
// If name is empty, fill it with the recognized text
|
134 |
+
nameInput.value = transcript;
|
135 |
+
status.textContent = 'Listening for your email...';
|
136 |
+
recognition.stop(); // Stop listening for name
|
137 |
+
recognition.start(); // Start listening for email
|
138 |
+
} else if (nameInput.value && !emailInput.value) {
|
139 |
+
// If email is empty, fill it with the recognized text
|
140 |
+
emailInput.value = transcript;
|
141 |
+
status.textContent = 'Registration complete.';
|
142 |
+
|
143 |
+
// After registration is complete, refresh page automatically after 15 seconds
|
144 |
+
setTimeout(() => location.reload(), 15000); // Refresh after 15 seconds
|
145 |
+
}
|
146 |
+
}
|
147 |
+
};
|
148 |
+
|
149 |
+
recognition.onerror = function(event) {
|
150 |
+
console.error('Speech recognition error:', event.error);
|
151 |
+
status.textContent = 'Error recognizing speech. Please try again.';
|
152 |
+
};
|
153 |
+
}
|
154 |
+
|
155 |
+
// Event listener for button to start listening
|
156 |
+
document.getElementById('status').addEventListener('click', startListening);
|
157 |
+
</script>
|
158 |
+
</body>
|
159 |
+
</html>
|