Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +51 -10
templates/index.html
CHANGED
@@ -363,9 +363,8 @@
|
|
363 |
chatBox.scrollTop = chatBox.scrollHeight;
|
364 |
}
|
365 |
|
366 |
-
|
367 |
-
|
368 |
-
// recognition.lang = 'en-US';
|
369 |
// Function to set language for speech recognition
|
370 |
function setRecognitionLanguage() {
|
371 |
const selectedLanguage = languageSelect.value;
|
@@ -376,22 +375,64 @@
|
|
376 |
case 'hindi':
|
377 |
recognition.lang = 'hi-IN'; // Hindi
|
378 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
default:
|
380 |
-
recognition.lang = 'en-US'; // English
|
381 |
break;
|
382 |
}
|
383 |
}
|
384 |
-
|
|
|
385 |
voiceBtn.addEventListener('click', () => {
|
386 |
setRecognitionLanguage(); // Set the language before starting speech recognition
|
387 |
recognition.start();
|
388 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
389 |
|
390 |
-
recognition.addEventListener('result', (e) => {
|
391 |
-
const transcript = e.results[0][0].transcript;
|
392 |
-
addMessage('user-message', transcript);
|
393 |
-
sendUserMessage(transcript);
|
394 |
-
});
|
395 |
|
396 |
// Function to change the accent color
|
397 |
function changeColor(color) {
|
|
|
363 |
chatBox.scrollTop = chatBox.scrollHeight;
|
364 |
}
|
365 |
|
366 |
+
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
367 |
+
|
|
|
368 |
// Function to set language for speech recognition
|
369 |
function setRecognitionLanguage() {
|
370 |
const selectedLanguage = languageSelect.value;
|
|
|
375 |
case 'hindi':
|
376 |
recognition.lang = 'hi-IN'; // Hindi
|
377 |
break;
|
378 |
+
case 'bengali':
|
379 |
+
recognition.lang = 'bn-IN'; // Bengali
|
380 |
+
break;
|
381 |
+
case 'marathi':
|
382 |
+
recognition.lang = 'mr-IN'; // Marathi
|
383 |
+
break;
|
384 |
+
case 'tamil':
|
385 |
+
recognition.lang = 'ta-IN'; // Tamil
|
386 |
+
break;
|
387 |
+
case 'gujarati':
|
388 |
+
recognition.lang = 'gu-IN'; // Gujarati
|
389 |
+
break;
|
390 |
+
case 'kannada':
|
391 |
+
recognition.lang = 'kn-IN'; // Kannada
|
392 |
+
break;
|
393 |
+
case 'malayalam':
|
394 |
+
recognition.lang = 'ml-IN'; // Malayalam
|
395 |
+
break;
|
396 |
+
case 'punjabi':
|
397 |
+
recognition.lang = 'pa-IN'; // Punjabi
|
398 |
+
break;
|
399 |
+
case 'odia':
|
400 |
+
recognition.lang = 'or-IN'; // Odia
|
401 |
+
break;
|
402 |
+
case 'urdu':
|
403 |
+
recognition.lang = 'ur-IN'; // Urdu
|
404 |
+
break;
|
405 |
+
case 'assamese':
|
406 |
+
recognition.lang = 'as-IN'; // Assamese
|
407 |
+
break;
|
408 |
+
case 'sanskrit':
|
409 |
+
recognition.lang = 'sa-IN'; // Sanskrit
|
410 |
+
break;
|
411 |
+
case 'english':
|
412 |
default:
|
413 |
+
recognition.lang = 'en-US'; // English (default)
|
414 |
break;
|
415 |
}
|
416 |
}
|
417 |
+
|
418 |
+
// Event listener for the voice input button
|
419 |
voiceBtn.addEventListener('click', () => {
|
420 |
setRecognitionLanguage(); // Set the language before starting speech recognition
|
421 |
recognition.start();
|
422 |
});
|
423 |
+
|
424 |
+
// Handle results from the speech recognition
|
425 |
+
recognition.addEventListener('result', (e) => {
|
426 |
+
const transcript = e.results[0][0].transcript;
|
427 |
+
addMessage('user-message', transcript);
|
428 |
+
sendUserMessage(transcript);
|
429 |
+
});
|
430 |
+
|
431 |
+
// Handle errors in speech recognition
|
432 |
+
recognition.addEventListener('error', (event) => {
|
433 |
+
console.error("Speech recognition error", event);
|
434 |
+
});
|
435 |
|
|
|
|
|
|
|
|
|
|
|
436 |
|
437 |
// Function to change the accent color
|
438 |
function changeColor(color) {
|