Spaces:
Runtime error
Runtime error
Gopikanth123
commited on
Update templates/index.html
Browse files- templates/index.html +26 -17
templates/index.html
CHANGED
@@ -466,7 +466,7 @@
|
|
466 |
.then(data => {
|
467 |
const botResponse = data.response;
|
468 |
addMessage('bot-message', botResponse);
|
469 |
-
speakResponse(botResponse);
|
470 |
})
|
471 |
.catch(error => {
|
472 |
console.error("Error:", error);
|
@@ -506,27 +506,36 @@
|
|
506 |
return voices.find(voice => voice.lang === lang) || null; // Find a matching voice or return null
|
507 |
}
|
508 |
|
509 |
-
// Enhanced Speak Function
|
510 |
-
function speak(text, lang) {
|
511 |
-
|
512 |
-
|
513 |
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
|
522 |
-
|
523 |
-
|
524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
525 |
}
|
526 |
|
527 |
// Language Handling Function
|
528 |
-
function speakResponse(text) {
|
529 |
-
const selectedLanguage = document.getElementById('language-select').value; // Get the selected language
|
|
|
530 |
let lang;
|
531 |
|
532 |
// Map selected language to appropriate language code
|
|
|
466 |
.then(data => {
|
467 |
const botResponse = data.response;
|
468 |
addMessage('bot-message', botResponse);
|
469 |
+
speakResponse(botResponse,selectedLanguage);
|
470 |
})
|
471 |
.catch(error => {
|
472 |
console.error("Error:", error);
|
|
|
506 |
return voices.find(voice => voice.lang === lang) || null; // Find a matching voice or return null
|
507 |
}
|
508 |
|
509 |
+
// // Enhanced Speak Function
|
510 |
+
// function speak(text, lang) {
|
511 |
+
// const utterance = new SpeechSynthesisUtterance(text);
|
512 |
+
// const selectedVoice = getVoiceForLanguage(lang);
|
513 |
|
514 |
+
// if (selectedVoice) {
|
515 |
+
// utterance.voice = selectedVoice; // Set the matching voice
|
516 |
+
// utterance.lang = lang; // Set the language
|
517 |
+
// } else {
|
518 |
+
// console.warn(`No voice found for language: ${lang}. Falling back to default.`);
|
519 |
+
// utterance.lang = 'en-US'; // Fallback to English
|
520 |
+
// }
|
521 |
|
522 |
+
// utterance.pitch = 1; // Set pitch (default: 1)
|
523 |
+
// utterance.rate = 1; // Set rate (default: 1)
|
524 |
+
// window.speechSynthesis.speak(utterance); // Speak the text
|
525 |
+
// }
|
526 |
+
// Text-to-Speech function
|
527 |
+
function speak(text, lang) {
|
528 |
+
const utterance = new SpeechSynthesisUtterance(text);
|
529 |
+
utterance.lang = lang;
|
530 |
+
utterance.pitch = 1;
|
531 |
+
utterance.rate = 1;
|
532 |
+
synth.speak(utterance);
|
533 |
}
|
534 |
|
535 |
// Language Handling Function
|
536 |
+
function speakResponse(text,selectedLanguage) {
|
537 |
+
// const selectedLanguage = document.getElementById('language-select').value; // Get the selected language
|
538 |
+
|
539 |
let lang;
|
540 |
|
541 |
// Map selected language to appropriate language code
|