Spaces:
Runtime error
Runtime error
Update templates/index.html
Browse files- templates/index.html +92 -63
templates/index.html
CHANGED
|
@@ -6,6 +6,7 @@
|
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
<title>TAJ HOTEL CHATBOT</title>
|
| 8 |
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
|
|
|
|
| 9 |
<style>
|
| 10 |
:root {
|
| 11 |
--primary-color: #007bff; /* Default blue */
|
|
@@ -501,77 +502,105 @@
|
|
| 501 |
// console.log(`Voice: ${voice.name}, Language: ${voice.lang}`);
|
| 502 |
// });
|
| 503 |
// };
|
| 504 |
-
// Function to initialize and fetch voices
|
| 505 |
-
function initializeVoices() {
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
}
|
| 517 |
|
| 518 |
-
// Function to get the voice for a given language
|
| 519 |
-
function getVoiceForLanguage(lang, voices) {
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
}
|
| 527 |
|
| 528 |
-
// Text-to-Speech function
|
| 529 |
-
async function speak(text, lang) {
|
| 530 |
-
|
| 531 |
-
|
| 532 |
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
}
|
| 546 |
|
| 547 |
// Language Handling Function
|
| 548 |
-
function speakResponse(text, selectedLanguage) {
|
| 549 |
-
let
|
| 550 |
-
switch (selectedLanguage.toLowerCase()) {
|
| 551 |
-
case 'hindi':
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
case '
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
case '
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
case '
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
case '
|
| 564 |
-
|
| 565 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 566 |
|
| 567 |
-
speak(text,
|
| 568 |
-
}
|
| 569 |
|
| 570 |
-
// Test voices and log them
|
| 571 |
-
initializeVoices().then(voices => {
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
});
|
| 575 |
// Event listeners for buttons
|
| 576 |
sendBtn.addEventListener('click', () => {
|
| 577 |
const message = userInput.value.trim();
|
|
|
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
<title>TAJ HOTEL CHATBOT</title>
|
| 8 |
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
|
| 9 |
+
<script src="https://code.responsivevoice.org/responsivevoice.js?key=q1DbMp6Z"></script>
|
| 10 |
<style>
|
| 11 |
:root {
|
| 12 |
--primary-color: #007bff; /* Default blue */
|
|
|
|
| 502 |
// console.log(`Voice: ${voice.name}, Language: ${voice.lang}`);
|
| 503 |
// });
|
| 504 |
// };
|
| 505 |
+
// // Function to initialize and fetch voices
|
| 506 |
+
// function initializeVoices() {
|
| 507 |
+
// return new Promise((resolve) => {
|
| 508 |
+
// const voices = window.speechSynthesis.getVoices();
|
| 509 |
+
// if (voices.length) {
|
| 510 |
+
// resolve(voices);
|
| 511 |
+
// } else {
|
| 512 |
+
// window.speechSynthesis.onvoiceschanged = () => {
|
| 513 |
+
// resolve(window.speechSynthesis.getVoices());
|
| 514 |
+
// };
|
| 515 |
+
// }
|
| 516 |
+
// });
|
| 517 |
+
// }
|
| 518 |
|
| 519 |
+
// // Function to get the voice for a given language
|
| 520 |
+
// function getVoiceForLanguage(lang, voices) {
|
| 521 |
+
// const voice = voices.find(voice => voice.lang === lang);
|
| 522 |
+
// if (voice) {
|
| 523 |
+
// return voice;
|
| 524 |
+
// }
|
| 525 |
+
// console.warn(`No voice found for language: ${lang}.`);
|
| 526 |
+
// return null;
|
| 527 |
+
// }
|
| 528 |
|
| 529 |
+
// // Text-to-Speech function
|
| 530 |
+
// async function speak(text, lang) {
|
| 531 |
+
// const voices = await initializeVoices();
|
| 532 |
+
// const selectedVoice = getVoiceForLanguage(lang, voices);
|
| 533 |
|
| 534 |
+
// const utterance = new SpeechSynthesisUtterance(text);
|
| 535 |
+
// if (selectedVoice) {
|
| 536 |
+
// utterance.voice = selectedVoice;
|
| 537 |
+
// utterance.lang = selectedVoice.lang;
|
| 538 |
+
// } else {
|
| 539 |
+
// console.warn(`Falling back to default language.`);
|
| 540 |
+
// utterance.lang = 'en-US';
|
| 541 |
+
// }
|
| 542 |
|
| 543 |
+
// utterance.pitch = 1; // Set pitch
|
| 544 |
+
// utterance.rate = 1; // Set rate
|
| 545 |
+
// window.speechSynthesis.speak(utterance); // Speak the text
|
| 546 |
+
// }
|
| 547 |
|
| 548 |
// Language Handling Function
|
| 549 |
+
function speakResponse(text, selectedLanguage) {
|
| 550 |
+
let voice;
|
| 551 |
+
switch (selectedLanguage.toLowerCase()) {
|
| 552 |
+
case 'hindi':
|
| 553 |
+
voice = 'Hindi Female'; // Use ResponsiveVoice voice name
|
| 554 |
+
break;
|
| 555 |
+
case 'bengali':
|
| 556 |
+
voice = 'Bengali Female'; // Use ResponsiveVoice voice name
|
| 557 |
+
break;
|
| 558 |
+
case 'telugu':
|
| 559 |
+
voice = 'Telugu Female'; // Use ResponsiveVoice voice name
|
| 560 |
+
break;
|
| 561 |
+
case 'marathi':
|
| 562 |
+
voice = 'Marathi Female'; // Use ResponsiveVoice voice name
|
| 563 |
+
break;
|
| 564 |
+
case 'tamil':
|
| 565 |
+
voice = 'Tamil Female'; // Use ResponsiveVoice voice name
|
| 566 |
+
break;
|
| 567 |
+
case 'gujarati':
|
| 568 |
+
voice = 'Gujarati Female'; // Use ResponsiveVoice voice name
|
| 569 |
+
break;
|
| 570 |
+
case 'kannada':
|
| 571 |
+
voice = 'Kannada Female'; // Use ResponsiveVoice voice name
|
| 572 |
+
break;
|
| 573 |
+
case 'malayalam':
|
| 574 |
+
voice = 'Malayalam Female'; // Use ResponsiveVoice voice name
|
| 575 |
+
break;
|
| 576 |
+
case 'punjabi':
|
| 577 |
+
voice = 'Punjabi Female'; // Use ResponsiveVoice voice name
|
| 578 |
+
break;
|
| 579 |
+
case 'odia':
|
| 580 |
+
voice = 'Odia Female'; // Use ResponsiveVoice voice name
|
| 581 |
+
break;
|
| 582 |
+
case 'urdu':
|
| 583 |
+
voice = 'Urdu Female'; // Use ResponsiveVoice voice name
|
| 584 |
+
break;
|
| 585 |
+
case 'assamese':
|
| 586 |
+
voice = 'Assamese Female'; // Use ResponsiveVoice voice name
|
| 587 |
+
break;
|
| 588 |
+
case 'sanskrit':
|
| 589 |
+
voice = 'Sanskrit Female'; // Use ResponsiveVoice voice name
|
| 590 |
+
break;
|
| 591 |
+
default:
|
| 592 |
+
voice = 'English US Female'; // Use ResponsiveVoice default voice name
|
| 593 |
+
break;
|
| 594 |
+
}
|
| 595 |
|
| 596 |
+
responsiveVoice.speak(text, voice); // Call ResponsiveVoice speak function with the determined voice
|
| 597 |
+
}
|
| 598 |
|
| 599 |
+
// // Test voices and log them
|
| 600 |
+
// initializeVoices().then(voices => {
|
| 601 |
+
// console.log("Available voices:");
|
| 602 |
+
// voices.forEach(voice => console.log(`Voice: ${voice.name}, Language: ${voice.lang}`));
|
| 603 |
+
// });
|
| 604 |
// Event listeners for buttons
|
| 605 |
sendBtn.addEventListener('click', () => {
|
| 606 |
const message = userInput.value.trim();
|