Spaces:
Sleeping
Sleeping
Update static/index.html
Browse files- static/index.html +24 -4
static/index.html
CHANGED
|
@@ -158,10 +158,30 @@
|
|
| 158 |
|
| 159 |
// Play speech using SpeechSynthesis API
|
| 160 |
function playAudio(text) {
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
// Speech-to-Text function
|
| 167 |
function startListening() {
|
|
|
|
| 158 |
|
| 159 |
// Play speech using SpeechSynthesis API
|
| 160 |
function playAudio(text) {
|
| 161 |
+
const utterance = new SpeechSynthesisUtterance(text);
|
| 162 |
+
const voices = window.speechSynthesis.getVoices();
|
| 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() {
|