Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +16 -0
templates/index.html
CHANGED
|
@@ -97,6 +97,22 @@
|
|
| 97 |
}
|
| 98 |
chat.appendChild(botRow);
|
| 99 |
chat.scrollTop = chat.scrollHeight;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
})
|
| 101 |
.catch(error => {
|
| 102 |
chat.removeChild(botTypingRow);
|
|
|
|
| 97 |
}
|
| 98 |
chat.appendChild(botRow);
|
| 99 |
chat.scrollTop = chat.scrollHeight;
|
| 100 |
+
// Request TTS for the bot response and play it
|
| 101 |
+
try {
|
| 102 |
+
fetch('/text_to_speech', {
|
| 103 |
+
method: 'POST',
|
| 104 |
+
headers: { 'Content-Type': 'application/json' },
|
| 105 |
+
body: JSON.stringify({ text: data.response, lang: 'auto' })
|
| 106 |
+
})
|
| 107 |
+
.then(r => r.json())
|
| 108 |
+
.then(t => {
|
| 109 |
+
if (t && t.tts_url) {
|
| 110 |
+
const audio = new Audio(t.tts_url);
|
| 111 |
+
audio.play().catch(()=>{});
|
| 112 |
+
}
|
| 113 |
+
})
|
| 114 |
+
.catch(()=>{});
|
| 115 |
+
} catch(e){}
|
| 116 |
})
|
| 117 |
.catch(error => {
|
| 118 |
chat.removeChild(botTypingRow);
|