Spaces:
Runtime error
Runtime error
Update templates/index.html
Browse files- templates/index.html +73 -35
templates/index.html
CHANGED
|
@@ -354,9 +354,27 @@
|
|
| 354 |
|
| 355 |
// Speech Recognition Setup
|
| 356 |
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
| 357 |
-
recognition.lang = 'en-US';
|
| 358 |
-
|
| 359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
recognition.addEventListener('result', (e) => {
|
| 362 |
const transcript = e.results[0][0].transcript;
|
|
@@ -404,39 +422,59 @@
|
|
| 404 |
});
|
| 405 |
}
|
| 406 |
|
| 407 |
-
// Text-to-Speech Function
|
| 408 |
-
function speakResponse(text) {
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
}
|
| 413 |
-
// Event listeners for buttons
|
| 414 |
-
sendBtn.addEventListener('click', () => {
|
| 415 |
-
const message = userInput.value.trim();
|
| 416 |
-
if (message) {
|
| 417 |
-
addMessage('user-message', message);
|
| 418 |
-
sendUserMessage(message);
|
| 419 |
-
userInput.value = ''; // Clear input field after sending
|
| 420 |
-
}
|
| 421 |
-
});
|
| 422 |
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
|
|
|
| 438 |
|
| 439 |
-
|
| 440 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
|
| 442 |
-
|
|
|
|
|
|
|
|
|
| 354 |
|
| 355 |
// Speech Recognition Setup
|
| 356 |
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
| 357 |
+
// recognition.lang = 'en-US';
|
| 358 |
+
// Function to set language for speech recognition
|
| 359 |
+
function setRecognitionLanguage() {
|
| 360 |
+
const selectedLanguage = languageSelect.value;
|
| 361 |
+
switch (selectedLanguage) {
|
| 362 |
+
case 'telugu':
|
| 363 |
+
recognition.lang = 'te-IN'; // Telugu
|
| 364 |
+
break;
|
| 365 |
+
case 'hindi':
|
| 366 |
+
recognition.lang = 'hi-IN'; // Hindi
|
| 367 |
+
break;
|
| 368 |
+
default:
|
| 369 |
+
recognition.lang = 'en-US'; // English
|
| 370 |
+
break;
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
// voiceBtn.addEventListener('click', () => recognition.start());
|
| 374 |
+
voiceBtn.addEventListener('click', () => {
|
| 375 |
+
setRecognitionLanguage(); // Set the language before starting speech recognition
|
| 376 |
+
recognition.start();
|
| 377 |
+
});
|
| 378 |
|
| 379 |
recognition.addEventListener('result', (e) => {
|
| 380 |
const transcript = e.results[0][0].transcript;
|
|
|
|
| 422 |
});
|
| 423 |
}
|
| 424 |
|
| 425 |
+
// // Text-to-Speech Function
|
| 426 |
+
// function speakResponse(text) {
|
| 427 |
+
// const utterance = new SpeechSynthesisUtterance(text);
|
| 428 |
+
// utterance.lang = 'en-US';
|
| 429 |
+
// window.speechSynthesis.speak(utterance);
|
| 430 |
+
// }
|
| 431 |
+
// Text-to-Speech Function
|
| 432 |
+
function speakResponse(text) {
|
| 433 |
+
const utterance = new SpeechSynthesisUtterance(text);
|
| 434 |
+
|
| 435 |
+
// Set the language for text-to-speech based on the selected language
|
| 436 |
+
const selectedLanguage = languageSelect.value;
|
| 437 |
+
switch (selectedLanguage) {
|
| 438 |
+
case 'telugu':
|
| 439 |
+
utterance.lang = 'te-IN'; // Telugu
|
| 440 |
+
break;
|
| 441 |
+
case 'hindi':
|
| 442 |
+
utterance.lang = 'hi-IN'; // Hindi
|
| 443 |
+
break;
|
| 444 |
+
default:
|
| 445 |
+
utterance.lang = 'en-US'; // English
|
| 446 |
+
break;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
window.speechSynthesis.speak(utterance);
|
| 450 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
|
| 452 |
+
// Event listeners for buttons
|
| 453 |
+
sendBtn.addEventListener('click', () => {
|
| 454 |
+
const message = userInput.value.trim();
|
| 455 |
+
if (message) {
|
| 456 |
+
addMessage('user-message', message);
|
| 457 |
+
sendUserMessage(message);
|
| 458 |
+
userInput.value = ''; // Clear input field after sending
|
| 459 |
+
}
|
| 460 |
+
});
|
| 461 |
+
|
| 462 |
+
// Handle pressing 'Enter' key for sending messages
|
| 463 |
+
userInput.addEventListener('keypress', (e) => {
|
| 464 |
+
if (e.key === 'Enter') {
|
| 465 |
+
sendBtn.click(); // Trigger button click
|
| 466 |
+
}
|
| 467 |
+
});
|
| 468 |
|
| 469 |
+
// Update theme when selected from dropdown
|
| 470 |
+
themeSelect.addEventListener('change', (e) => {
|
| 471 |
+
changeTheme(e.target.value);
|
| 472 |
+
});
|
| 473 |
+
|
| 474 |
+
recognition.addEventListener('error', (event) => {
|
| 475 |
+
console.error("Speech recognition error", event);
|
| 476 |
+
});
|
| 477 |
|
| 478 |
+
</script>
|
| 479 |
+
</body>
|
| 480 |
+
</html>
|