Spaces:
Sleeping
Sleeping
Update static/index.html
Browse files- static/index.html +8 -27
static/index.html
CHANGED
|
@@ -147,7 +147,9 @@
|
|
| 147 |
const botMessage = data.response;
|
| 148 |
addMessage("Bot", botMessage, "bot-message");
|
| 149 |
chatHistoryArray.push({ sender: "Bot", message: botMessage });
|
| 150 |
-
|
|
|
|
|
|
|
| 151 |
} catch (error) {
|
| 152 |
botTyping.remove();
|
| 153 |
console.error("Error:", error);
|
|
@@ -156,32 +158,11 @@
|
|
| 156 |
}
|
| 157 |
}
|
| 158 |
|
| 159 |
-
// Play
|
| 160 |
-
function playAudio(
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
let selectedVoice = null;
|
| 165 |
-
|
| 166 |
-
// Try to find a Hindi or Telugu voice
|
| 167 |
-
if (currentLanguage === "hi-IN") {
|
| 168 |
-
selectedVoice = voices.find(voice => voice.lang === "hi-IN" || voice.name.toLowerCase().includes("hindi"));
|
| 169 |
-
} else if (currentLanguage === "te-IN") {
|
| 170 |
-
selectedVoice = voices.find(voice => voice.lang === "te-IN" || voice.name.toLowerCase().includes("telugu"));
|
| 171 |
-
}
|
| 172 |
-
|
| 173 |
-
// If a voice is found, use it
|
| 174 |
-
if (selectedVoice) {
|
| 175 |
-
utterance.voice = selectedVoice;
|
| 176 |
-
} else {
|
| 177 |
-
// Default to the first available voice if no specific voice is found
|
| 178 |
-
utterance.voice = voices[0];
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
-
// Speak the text
|
| 182 |
-
window.speechSynthesis.speak(utterance);
|
| 183 |
-
}
|
| 184 |
-
|
| 185 |
|
| 186 |
// Speech-to-Text function
|
| 187 |
function startListening() {
|
|
|
|
| 147 |
const botMessage = data.response;
|
| 148 |
addMessage("Bot", botMessage, "bot-message");
|
| 149 |
chatHistoryArray.push({ sender: "Bot", message: botMessage });
|
| 150 |
+
if (data.audioUrl) {
|
| 151 |
+
playAudio(data.audioUrl);
|
| 152 |
+
}
|
| 153 |
} catch (error) {
|
| 154 |
botTyping.remove();
|
| 155 |
console.error("Error:", error);
|
|
|
|
| 158 |
}
|
| 159 |
}
|
| 160 |
|
| 161 |
+
// Play audio from gTTS
|
| 162 |
+
function playAudio(url) {
|
| 163 |
+
const audio = new Audio(url);
|
| 164 |
+
audio.play();
|
| 165 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
// Speech-to-Text function
|
| 168 |
function startListening() {
|