Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +24 -27
templates/index.html
CHANGED
@@ -356,38 +356,35 @@
|
|
356 |
}
|
357 |
|
358 |
// Speech Recognition Setup
|
359 |
-
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
360 |
-
recognition.lang = 'en-US';
|
|
|
|
|
361 |
|
362 |
-
|
363 |
-
voiceBtn.addEventListener('click', () => recognition.start());
|
364 |
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
});
|
371 |
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
};
|
376 |
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
};
|
381 |
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
addMessage('system-message', 'An error occurred during speech recognition.');
|
389 |
-
}
|
390 |
-
};
|
391 |
|
392 |
|
393 |
// Function to change the accent color
|
|
|
356 |
}
|
357 |
|
358 |
// Speech Recognition Setup
|
359 |
+
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
360 |
+
recognition.lang = 'en-US';
|
361 |
+
recognition.maxResults = 10;
|
362 |
+
recognition.interimResults = true;
|
363 |
|
364 |
+
voiceBtn.addEventListener('click', () => recognition.start());
|
|
|
365 |
|
366 |
+
recognition.addEventListener('result', (e) => {
|
367 |
+
const transcript = e.results[0][0].transcript;
|
368 |
+
addMessage('user-message', transcript);
|
369 |
+
sendUserMessage(transcript);
|
370 |
+
});
|
|
|
371 |
|
372 |
+
recognition.addEventListener('noresult', () => {
|
373 |
+
addMessage('user-message', 'No speech detected');
|
374 |
+
sendUserMessage('No speech detected');
|
375 |
+
});
|
376 |
|
377 |
+
recognition.addEventListener('nomatch', () => {
|
378 |
+
addMessage('user-message', 'No speech detected');
|
379 |
+
sendUserMessage('No speech detected');
|
380 |
+
});
|
381 |
|
382 |
+
recognition.addEventListener('error', (e) => {
|
383 |
+
if(e.error == 'no-speech') {
|
384 |
+
addMessage('user-message', 'No speech detected');
|
385 |
+
sendUserMessage('No speech detected');
|
386 |
+
}
|
387 |
+
});
|
|
|
|
|
|
|
388 |
|
389 |
|
390 |
// Function to change the accent color
|