Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +70 -62
templates/index.html
CHANGED
@@ -459,68 +459,76 @@
|
|
459 |
|
460 |
// window.speechSynthesis.speak(utterance);
|
461 |
// }
|
462 |
-
//
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
524 |
|
525 |
|
526 |
// Event listeners for buttons
|
|
|
459 |
|
460 |
// window.speechSynthesis.speak(utterance);
|
461 |
// }
|
462 |
+
// Function to get the voice list and match language
|
463 |
+
function getVoiceForLanguage(lang) {
|
464 |
+
const voices = window.speechSynthesis.getVoices();
|
465 |
+
return voices.find(voice => voice.lang === lang) || null; // Find a matching voice or return null
|
466 |
+
}
|
467 |
+
|
468 |
+
// Enhanced Speak Function
|
469 |
+
function speak(text, lang) {
|
470 |
+
const utterance = new SpeechSynthesisUtterance(text);
|
471 |
+
const selectedVoice = getVoiceForLanguage(lang);
|
472 |
+
|
473 |
+
if (selectedVoice) {
|
474 |
+
utterance.voice = selectedVoice; // Set the matching voice
|
475 |
+
utterance.lang = lang; // Set the language
|
476 |
+
} else {
|
477 |
+
console.warn(`No voice found for language: ${lang}. Falling back to default.`);
|
478 |
+
utterance.lang = 'en-US'; // Fallback to English
|
479 |
+
}
|
480 |
+
|
481 |
+
utterance.pitch = 1; // Set pitch (default: 1)
|
482 |
+
utterance.rate = 1; // Set rate (default: 1)
|
483 |
+
window.speechSynthesis.speak(utterance); // Speak the text
|
484 |
+
}
|
485 |
+
|
486 |
+
// Language Handling Function
|
487 |
+
function speakResponse(text) {
|
488 |
+
const selectedLanguage = document.getElementById('language-select').value; // Get the selected language
|
489 |
+
let lang;
|
490 |
+
|
491 |
+
// Map selected language to appropriate language code
|
492 |
+
switch (selectedLanguage) {
|
493 |
+
case 'hindi':
|
494 |
+
lang = 'hi-IN'; break;
|
495 |
+
case 'bengali':
|
496 |
+
lang = 'bn-IN'; break;
|
497 |
+
case 'telugu':
|
498 |
+
lang = 'te-IN'; break;
|
499 |
+
case 'marathi':
|
500 |
+
lang = 'mr-IN'; break;
|
501 |
+
case 'tamil':
|
502 |
+
lang = 'ta-IN'; break;
|
503 |
+
case 'gujarati':
|
504 |
+
lang = 'gu-IN'; break;
|
505 |
+
case 'kannada':
|
506 |
+
lang = 'kn-IN'; break;
|
507 |
+
case 'malayalam':
|
508 |
+
lang = 'ml-IN'; break;
|
509 |
+
case 'punjabi':
|
510 |
+
lang = 'pa-IN'; break;
|
511 |
+
case 'odia':
|
512 |
+
lang = 'or-IN'; break;
|
513 |
+
case 'urdu':
|
514 |
+
lang = 'ur-IN'; break;
|
515 |
+
case 'assamese':
|
516 |
+
lang = 'as-IN'; break;
|
517 |
+
case 'sanskrit':
|
518 |
+
lang = 'sa-IN'; break;
|
519 |
+
default:
|
520 |
+
lang = 'en-US'; break; // English (default)
|
521 |
+
}
|
522 |
+
|
523 |
+
speak(text, lang); // Call the speak function with the determined language
|
524 |
+
}
|
525 |
+
|
526 |
+
// Ensure voices are loaded before running the TTS
|
527 |
+
if (window.speechSynthesis.onvoiceschanged !== undefined) {
|
528 |
+
window.speechSynthesis.onvoiceschanged = () => {
|
529 |
+
console.log("Voices loaded and ready to use.");
|
530 |
+
};
|
531 |
+
}
|
532 |
|
533 |
|
534 |
// Event listeners for buttons
|