Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +66 -12
templates/index.html
CHANGED
@@ -303,7 +303,19 @@
|
|
303 |
<option value="soft-lavender">Soft Lavender</option>
|
304 |
<option value="bright-summer">Bright Summer</option>
|
305 |
</select>
|
306 |
-
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
<div class="color-picker">
|
308 |
<label>Accent Color:</label>
|
309 |
<div class="color-circle" style="background-color: #6a0dad;" onclick="changeColor('#6a0dad')"></div>
|
@@ -343,17 +355,40 @@
|
|
343 |
chatBox.scrollTop = chatBox.scrollHeight;
|
344 |
}
|
345 |
|
346 |
-
// Speech Recognition Setup
|
347 |
-
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
348 |
-
recognition.lang = 'en-US';
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
|
358 |
// Function to change the accent color
|
359 |
function changeColor(color) {
|
@@ -420,6 +455,25 @@
|
|
420 |
recognition.addEventListener('error', (event) => {
|
421 |
console.error("Speech recognition error", event);
|
422 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
423 |
|
424 |
</script>
|
425 |
</body>
|
|
|
303 |
<option value="soft-lavender">Soft Lavender</option>
|
304 |
<option value="bright-summer">Bright Summer</option>
|
305 |
</select>
|
306 |
+
</div>
|
307 |
+
<div class="language-toggle">
|
308 |
+
<label for="language-select">Select Language:</label>
|
309 |
+
<select id="language-select">
|
310 |
+
<option value="en">English</option>
|
311 |
+
<option value="es">Spanish</option>
|
312 |
+
<option value="fr">French</option>
|
313 |
+
<option value="de">German</option>
|
314 |
+
<option value="hi">Hindi</option>
|
315 |
+
<option value="zh">Chinese</option>
|
316 |
+
<option value="ar">Arabic</option>
|
317 |
+
</select>
|
318 |
+
</div>
|
319 |
<div class="color-picker">
|
320 |
<label>Accent Color:</label>
|
321 |
<div class="color-circle" style="background-color: #6a0dad;" onclick="changeColor('#6a0dad')"></div>
|
|
|
355 |
chatBox.scrollTop = chatBox.scrollHeight;
|
356 |
}
|
357 |
|
358 |
+
// Speech Recognition Setup
|
359 |
+
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
360 |
+
recognition.lang = 'en-US';
|
361 |
+
|
362 |
+
// Start recognition when the voice button is clicked
|
363 |
+
voiceBtn.addEventListener('click', () => recognition.start());
|
364 |
+
|
365 |
+
// Handle successful speech recognition
|
366 |
+
recognition.addEventListener('result', (e) => {
|
367 |
+
const transcript = e.results[0][0].transcript;
|
368 |
+
addMessage('user-message', transcript);
|
369 |
+
sendUserMessage(transcript);
|
370 |
+
});
|
371 |
+
|
372 |
+
// Handle when speech ends without detection
|
373 |
+
recognition.onspeechend = () => {
|
374 |
+
recognition.stop(); // Stop recognition to prevent hanging
|
375 |
+
};
|
376 |
+
|
377 |
+
// Handle no match (e.g., no recognizable speech detected)
|
378 |
+
recognition.onnomatch = () => {
|
379 |
+
addMessage('system-message', 'Speech not detected. Please try again.');
|
380 |
+
};
|
381 |
+
|
382 |
+
// Handle errors during speech recognition
|
383 |
+
recognition.onerror = (event) => {
|
384 |
+
console.error('Speech recognition error:', event.error);
|
385 |
+
if (event.error === 'no-speech') {
|
386 |
+
addMessage('system-message', 'No speech detected. Please speak clearly and try again.');
|
387 |
+
} else {
|
388 |
+
addMessage('system-message', 'An error occurred during speech recognition.');
|
389 |
+
}
|
390 |
+
};
|
391 |
+
|
392 |
|
393 |
// Function to change the accent color
|
394 |
function changeColor(color) {
|
|
|
455 |
recognition.addEventListener('error', (event) => {
|
456 |
console.error("Speech recognition error", event);
|
457 |
});
|
458 |
+
// Event listener for language selection
|
459 |
+
document.getElementById("language-select").addEventListener("change", function () {
|
460 |
+
const selectedLanguage = this.value;
|
461 |
+
|
462 |
+
// Example: Display a message when the language is changed
|
463 |
+
console.log(`Language selected: ${selectedLanguage}`);
|
464 |
+
|
465 |
+
// Logic to change chatbot responses based on the selected language
|
466 |
+
// You can call an API to fetch translations or configure response logic here.
|
467 |
+
// For example:
|
468 |
+
updateBotLanguage(selectedLanguage);
|
469 |
+
});
|
470 |
+
|
471 |
+
// Function to handle language-specific logic
|
472 |
+
function updateBotLanguage(language) {
|
473 |
+
// Placeholder function for your chatbot's language integration
|
474 |
+
alert(`Chatbot will now respond in: ${language.toUpperCase()}`);
|
475 |
+
// Integrate language translations for bot messages here.
|
476 |
+
}
|
477 |
|
478 |
</script>
|
479 |
</body>
|