Spaces:
Sleeping
Sleeping
Update static/index.html
Browse files- static/index.html +18 -2
static/index.html
CHANGED
@@ -164,18 +164,34 @@
|
|
164 |
|
165 |
// Speech-to-Text function
|
166 |
function startListening() {
|
167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
recognition.lang = currentLanguage;
|
169 |
recognition.interimResults = false;
|
|
|
170 |
recognition.onresult = (event) => {
|
171 |
const transcript = event.results[0][0].transcript;
|
172 |
document.getElementById("user-input").value = transcript;
|
173 |
sendMessage();
|
174 |
};
|
|
|
175 |
recognition.onerror = (event) => {
|
176 |
console.error("Speech recognition error:", event.error);
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
};
|
|
|
179 |
recognition.start();
|
180 |
}
|
181 |
|
|
|
164 |
|
165 |
// Speech-to-Text function
|
166 |
function startListening() {
|
167 |
+
let recognition;
|
168 |
+
if (window.SpeechRecognition || window.webkitSpeechRecognition) {
|
169 |
+
recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
170 |
+
} else {
|
171 |
+
alert("Your browser does not support speech recognition.");
|
172 |
+
return;
|
173 |
+
}
|
174 |
+
|
175 |
recognition.lang = currentLanguage;
|
176 |
recognition.interimResults = false;
|
177 |
+
|
178 |
recognition.onresult = (event) => {
|
179 |
const transcript = event.results[0][0].transcript;
|
180 |
document.getElementById("user-input").value = transcript;
|
181 |
sendMessage();
|
182 |
};
|
183 |
+
|
184 |
recognition.onerror = (event) => {
|
185 |
console.error("Speech recognition error:", event.error);
|
186 |
+
let errorMessage = "Sorry, I couldn't understand you.";
|
187 |
+
if (event.error === "not-allowed") {
|
188 |
+
errorMessage = "Microphone access is blocked. Please allow access.";
|
189 |
+
} else if (event.error === "network") {
|
190 |
+
errorMessage = "Network error. Please check your connection.";
|
191 |
+
}
|
192 |
+
addMessage("Bot", errorMessage, "bot-message");
|
193 |
};
|
194 |
+
|
195 |
recognition.start();
|
196 |
}
|
197 |
|