Spaces:
Runtime error
Runtime error
Update templates/index.html
Browse files- templates/index.html +117 -43
templates/index.html
CHANGED
|
@@ -327,9 +327,20 @@
|
|
| 327 |
|
| 328 |
<!-- Language dropdown -->
|
| 329 |
<select id="language-select">
|
| 330 |
-
<option value="english"
|
| 331 |
-
<option value="telugu">Telugu</option>
|
| 332 |
<option value="hindi">Hindi</option>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
</select>
|
| 334 |
</div>
|
| 335 |
|
|
@@ -429,51 +440,114 @@
|
|
| 429 |
// window.speechSynthesis.speak(utterance);
|
| 430 |
// }
|
| 431 |
// Text-to-Speech Function
|
| 432 |
-
function speakResponse(text) {
|
| 433 |
-
|
| 434 |
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
|
| 449 |
-
|
| 450 |
-
}
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 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 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 477 |
|
| 478 |
</script>
|
| 479 |
</body>
|
|
|
|
| 327 |
|
| 328 |
<!-- Language dropdown -->
|
| 329 |
<select id="language-select">
|
| 330 |
+
<option value="english">English</option>
|
|
|
|
| 331 |
<option value="hindi">Hindi</option>
|
| 332 |
+
<option value="bengali">Bengali</option>
|
| 333 |
+
<option value="telugu">Telugu</option>
|
| 334 |
+
<option value="marathi">Marathi</option>
|
| 335 |
+
<option value="tamil">Tamil</option>
|
| 336 |
+
<option value="gujarati">Gujarati</option>
|
| 337 |
+
<option value="kannada">Kannada</option>
|
| 338 |
+
<option value="malayalam">Malayalam</option>
|
| 339 |
+
<option value="punjabi">Punjabi</option>
|
| 340 |
+
<option value="odia">Odia</option>
|
| 341 |
+
<option value="urdu">Urdu</option>
|
| 342 |
+
<option value="assamese">Assamese</option>
|
| 343 |
+
<option value="sanskrit">Sanskrit</option>
|
| 344 |
</select>
|
| 345 |
</div>
|
| 346 |
|
|
|
|
| 440 |
// window.speechSynthesis.speak(utterance);
|
| 441 |
// }
|
| 442 |
// Text-to-Speech Function
|
| 443 |
+
// function speakResponse(text) {
|
| 444 |
+
// const utterance = new SpeechSynthesisUtterance(text);
|
| 445 |
|
| 446 |
+
// // Set the language for text-to-speech based on the selected language
|
| 447 |
+
// const selectedLanguage = languageSelect.value;
|
| 448 |
+
// switch (selectedLanguage) {
|
| 449 |
+
// case 'telugu':
|
| 450 |
+
// utterance.lang = 'te-IN'; // Telugu
|
| 451 |
+
// break;
|
| 452 |
+
// case 'hindi':
|
| 453 |
+
// utterance.lang = 'hi-IN'; // Hindi
|
| 454 |
+
// break;
|
| 455 |
+
// default:
|
| 456 |
+
// utterance.lang = 'en-US'; // English
|
| 457 |
+
// break;
|
| 458 |
+
// }
|
| 459 |
|
| 460 |
+
// window.speechSynthesis.speak(utterance);
|
| 461 |
+
// }
|
| 462 |
+
// Text-to-Speech function
|
| 463 |
+
function speak(text, lang) {
|
| 464 |
+
const utterance = new SpeechSynthesisUtterance(text);
|
| 465 |
+
utterance.lang = lang; // Set language
|
| 466 |
+
utterance.pitch = 1; // Set pitch (default: 1)
|
| 467 |
+
utterance.rate = 1; // Set rate (default: 1)
|
| 468 |
+
window.speechSynthesis.speak(utterance); // Speak the text
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
// Language handling function
|
| 472 |
+
function speakResponse(text) {
|
| 473 |
+
const selectedLanguage = document.getElementById('language-select').value; // Get the selected language
|
| 474 |
+
let lang;
|
| 475 |
+
|
| 476 |
+
// Map selected language to appropriate language code
|
| 477 |
+
switch (selectedLanguage) {
|
| 478 |
+
case 'hindi':
|
| 479 |
+
lang = 'hi-IN'; // Hindi
|
| 480 |
+
break;
|
| 481 |
+
case 'bengali':
|
| 482 |
+
lang = 'bn-IN'; // Bengali
|
| 483 |
+
break;
|
| 484 |
+
case 'telugu':
|
| 485 |
+
lang = 'te-IN'; // Telugu
|
| 486 |
+
break;
|
| 487 |
+
case 'marathi':
|
| 488 |
+
lang = 'mr-IN'; // Marathi
|
| 489 |
+
break;
|
| 490 |
+
case 'tamil':
|
| 491 |
+
lang = 'ta-IN'; // Tamil
|
| 492 |
+
break;
|
| 493 |
+
case 'gujarati':
|
| 494 |
+
lang = 'gu-IN'; // Gujarati
|
| 495 |
+
break;
|
| 496 |
+
case 'kannada':
|
| 497 |
+
lang = 'kn-IN'; // Kannada
|
| 498 |
+
break;
|
| 499 |
+
case 'malayalam':
|
| 500 |
+
lang = 'ml-IN'; // Malayalam
|
| 501 |
+
break;
|
| 502 |
+
case 'punjabi':
|
| 503 |
+
lang = 'pa-IN'; // Punjabi
|
| 504 |
+
break;
|
| 505 |
+
case 'odia':
|
| 506 |
+
lang = 'or-IN'; // Odia
|
| 507 |
+
break;
|
| 508 |
+
case 'urdu':
|
| 509 |
+
lang = 'ur-IN'; // Urdu
|
| 510 |
+
break;
|
| 511 |
+
case 'assamese':
|
| 512 |
+
lang = 'as-IN'; // Assamese
|
| 513 |
+
break;
|
| 514 |
+
case 'sanskrit':
|
| 515 |
+
lang = 'sa-IN'; // Sanskrit
|
| 516 |
+
break;
|
| 517 |
+
default:
|
| 518 |
+
lang = 'en-US'; // English (default)
|
| 519 |
+
break;
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
speak(text, lang); // Call the speak function with the determined language
|
| 523 |
+
}
|
| 524 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
|
| 526 |
+
// Event listeners for buttons
|
| 527 |
+
sendBtn.addEventListener('click', () => {
|
| 528 |
+
const message = userInput.value.trim();
|
| 529 |
+
if (message) {
|
| 530 |
+
addMessage('user-message', message);
|
| 531 |
+
sendUserMessage(message);
|
| 532 |
+
userInput.value = ''; // Clear input field after sending
|
| 533 |
+
}
|
| 534 |
+
});
|
| 535 |
+
|
| 536 |
+
// Handle pressing 'Enter' key for sending messages
|
| 537 |
+
userInput.addEventListener('keypress', (e) => {
|
| 538 |
+
if (e.key === 'Enter') {
|
| 539 |
+
sendBtn.click(); // Trigger button click
|
| 540 |
+
}
|
| 541 |
+
});
|
| 542 |
+
|
| 543 |
+
// Update theme when selected from dropdown
|
| 544 |
+
themeSelect.addEventListener('change', (e) => {
|
| 545 |
+
changeTheme(e.target.value);
|
| 546 |
+
});
|
| 547 |
+
|
| 548 |
+
recognition.addEventListener('error', (event) => {
|
| 549 |
+
console.error("Speech recognition error", event);
|
| 550 |
+
});
|
| 551 |
|
| 552 |
</script>
|
| 553 |
</body>
|