Gopikanth123 commited on
Commit
e2a12fe
·
verified ·
1 Parent(s): 2178a82

Update templates/index.html

Browse files
Files changed (1) hide show
  1. 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" selected>English</option>
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
- 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>
 
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>