Spaces:
Running
Running
Update index.html
Browse files- index.html +146 -154
index.html
CHANGED
|
@@ -1,162 +1,154 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
</head>
|
| 38 |
<body>
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
<button id="speech" onclick="runSpeechRecog()" style="border: transparent; padding: 0 0.5rem;">
|
| 55 |
-
Tap to Speak
|
| 56 |
-
</button>
|
| 57 |
-
</div>
|
| 58 |
</div>
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
synth.speak(utterance);
|
| 146 |
-
|
| 147 |
-
window.addEventListener('beforeunload', function () {
|
| 148 |
-
if (synth.speaking) synth.cancel();
|
| 149 |
-
});
|
| 150 |
-
|
| 151 |
-
document.getElementById('speech').addEventListener('click', function () {
|
| 152 |
-
if (synth.speaking) synth.cancel();
|
| 153 |
-
});
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
// Load voices early for compatibility
|
| 157 |
-
window.speechSynthesis.onvoiceschanged = () => {
|
| 158 |
-
speechSynthesis.getVoices();
|
| 159 |
-
};
|
| 160 |
-
</script>
|
| 161 |
</body>
|
| 162 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<title>Voice Command | Chatbot</title>
|
| 6 |
+
<style>
|
| 7 |
+
.chat-container {
|
| 8 |
+
max-width: 400px;
|
| 9 |
+
margin: 20px auto;
|
| 10 |
+
padding: 10px;
|
| 11 |
+
border: 1px solid #ccc;
|
| 12 |
+
border-radius: 5px;
|
| 13 |
+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
| 14 |
+
font-family: Arial, sans-serif;
|
| 15 |
+
}
|
| 16 |
+
.user-message, .bot-message {
|
| 17 |
+
border-radius: 5px;
|
| 18 |
+
padding: 5px 10px;
|
| 19 |
+
margin: 5px 0;
|
| 20 |
+
}
|
| 21 |
+
.user-message {
|
| 22 |
+
background-color: #f0f0f0;
|
| 23 |
+
text-align: right;
|
| 24 |
+
}
|
| 25 |
+
.bot-message {
|
| 26 |
+
background-color: #d3e9ff;
|
| 27 |
+
}
|
| 28 |
+
#languageSelector {
|
| 29 |
+
width: 100%;
|
| 30 |
+
margin-top: 10px;
|
| 31 |
+
padding: 5px;
|
| 32 |
+
border-radius: 5px;
|
| 33 |
+
border: 1px solid #ccc;
|
| 34 |
+
}
|
| 35 |
+
.speaker {
|
| 36 |
+
display: flex;
|
| 37 |
+
justify-content: space-between;
|
| 38 |
+
width: 100%;
|
| 39 |
+
box-shadow: 0 0 13px #0000003d;
|
| 40 |
+
border-radius: 5px;
|
| 41 |
+
margin-top: 10px;
|
| 42 |
+
}
|
| 43 |
+
#speech {
|
| 44 |
+
border: transparent;
|
| 45 |
+
padding: 0 0.5rem;
|
| 46 |
+
cursor: pointer;
|
| 47 |
+
}
|
| 48 |
+
</style>
|
| 49 |
</head>
|
| 50 |
<body>
|
| 51 |
+
<div class="chat-container">
|
| 52 |
+
<div id="chat-box"></div>
|
| 53 |
+
|
| 54 |
+
<select id="languageSelector">
|
| 55 |
+
<option value="en-US">English (US)</option>
|
| 56 |
+
<option value="hi-IN">Hindi (India)</option>
|
| 57 |
+
<option value="es-ES">Spanish (Spain)</option>
|
| 58 |
+
<option value="fr-FR">French (France)</option>
|
| 59 |
+
<option value="de-DE">German (Germany)</option>
|
| 60 |
+
<option value="ar-SA">Arabic (Saudi Arabia)</option>
|
| 61 |
+
</select>
|
| 62 |
+
|
| 63 |
+
<div class="speaker">
|
| 64 |
+
<p id="action" style="color: grey; font-weight: 800; padding-left: 2rem;"></p>
|
| 65 |
+
<button id="speech">Tap to Speak</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
</div>
|
| 67 |
+
</div>
|
| 68 |
+
|
| 69 |
+
<script>
|
| 70 |
+
const synth = window.speechSynthesis;
|
| 71 |
+
let recognition;
|
| 72 |
+
|
| 73 |
+
// Event listener for the button
|
| 74 |
+
document.getElementById("speech").addEventListener("click", () => {
|
| 75 |
+
runSpeechRecog();
|
| 76 |
+
});
|
| 77 |
+
|
| 78 |
+
function runSpeechRecog() {
|
| 79 |
+
const action = document.getElementById("action");
|
| 80 |
+
|
| 81 |
+
// Prevent multiple instances
|
| 82 |
+
if (recognition) recognition.abort();
|
| 83 |
+
|
| 84 |
+
// Ensure Chrome compatibility
|
| 85 |
+
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
| 86 |
+
if (!SpeechRecognition) {
|
| 87 |
+
alert("Speech Recognition not supported in this browser. Use Google Chrome.");
|
| 88 |
+
return;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
recognition = new SpeechRecognition();
|
| 92 |
+
recognition.lang = "en-US"; // Always English for input
|
| 93 |
+
recognition.interimResults = false;
|
| 94 |
+
recognition.continuous = false;
|
| 95 |
+
|
| 96 |
+
recognition.onstart = () => {
|
| 97 |
+
action.innerHTML = "Listening...";
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
+
recognition.onresult = (event) => {
|
| 101 |
+
const transcript = event.results[0][0].transcript;
|
| 102 |
+
action.innerHTML = "";
|
| 103 |
+
sendMessage(transcript);
|
| 104 |
+
};
|
| 105 |
+
|
| 106 |
+
recognition.onerror = (event) => {
|
| 107 |
+
action.innerHTML = "Error: " + event.error;
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
recognition.onend = () => {
|
| 111 |
+
action.innerHTML = "";
|
| 112 |
+
};
|
| 113 |
+
|
| 114 |
+
recognition.start();
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
function sendMessage(message) {
|
| 118 |
+
showUserMessage(message);
|
| 119 |
+
// Simulating response (replace with your backend call)
|
| 120 |
+
setTimeout(() => handleResponse("You said: " + message), 500);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
function showUserMessage(message) {
|
| 124 |
+
const chatBox = document.getElementById("chat-box");
|
| 125 |
+
chatBox.innerHTML += <div class="user-message">${message}</div>;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
function handleResponse(message) {
|
| 129 |
+
showBotMessage(message);
|
| 130 |
+
speakResponse(message);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
function showBotMessage(message) {
|
| 134 |
+
const chatBox = document.getElementById("chat-box");
|
| 135 |
+
chatBox.innerHTML += <div class="bot-message">${message}</div>;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
function speakResponse(responseText) {
|
| 139 |
+
const selectedLang = document.getElementById("languageSelector").value;
|
| 140 |
+
const utterance = new SpeechSynthesisUtterance(responseText);
|
| 141 |
+
utterance.lang = selectedLang;
|
| 142 |
+
|
| 143 |
+
const voices = synth.getVoices();
|
| 144 |
+
const match = voices.find(v => v.lang === selectedLang);
|
| 145 |
+
if (match) utterance.voice = match;
|
| 146 |
+
|
| 147 |
+
synth.speak(utterance);
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
// Ensure voices are loaded
|
| 151 |
+
window.speechSynthesis.onvoiceschanged = () => synth.getVoices();
|
| 152 |
+
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
</body>
|
| 154 |
</html>
|