redfernstech commited on
Commit
85d287a
·
verified ·
1 Parent(s): 2888165

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +6 -7
static/index.html CHANGED
@@ -147,9 +147,7 @@
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,10 +156,11 @@
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
 
147
  const botMessage = data.response;
148
  addMessage("Bot", botMessage, "bot-message");
149
  chatHistoryArray.push({ sender: "Bot", message: botMessage });
150
+ playAudio(botMessage); // Play the bot's response as speech
 
 
151
  } catch (error) {
152
  botTyping.remove();
153
  console.error("Error:", error);
 
156
  }
157
  }
158
 
159
+ // Play speech using SpeechSynthesis API
160
+ function playAudio(text) {
161
+ const utterance = new SpeechSynthesisUtterance(text);
162
+ utterance.lang = currentLanguage; // Ensure language is set correctly
163
+ window.speechSynthesis.speak(utterance);
164
  }
165
 
166
  // Speech-to-Text function