redfernstech commited on
Commit
b281dc7
·
verified ·
1 Parent(s): a09e5f2

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +25 -4
static/index.html CHANGED
@@ -159,10 +159,31 @@
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() {
 
159
  }
160
 
161
  // Play audio from gTTS
162
+ // Play audio from server response
163
+ function playAudio(url) {
164
+ if (!url) {
165
+ console.error("Audio URL is missing.");
166
+ addMessage("Bot", "Error: Unable to play audio.", "bot-message");
167
+ return;
168
+ }
169
+
170
+ const audio = new Audio(url);
171
+
172
+ audio.onerror = () => {
173
+ console.error("Error loading audio:", url);
174
+ addMessage("Bot", "Error: Unable to load audio.", "bot-message");
175
+ };
176
+
177
+ audio.onplay = () => {
178
+ console.log("Playing audio:", url);
179
+ };
180
+
181
+ audio.play().catch((error) => {
182
+ console.error("Error during audio playback:", error);
183
+ addMessage("Bot", "Error: Unable to play audio.", "bot-message");
184
+ });
185
+ }
186
+
187
 
188
  // Speech-to-Text function
189
  function startListening() {