ar08 commited on
Commit
4acb3ed
·
verified ·
1 Parent(s): a13ae14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -165,10 +165,27 @@ def create_demo():
165
  }
166
  }
167
 
168
- document.addEventListener('gradioAudioLoaded', function(event) {
169
- playAssistantAudio();
 
 
 
 
 
 
 
 
 
 
 
 
170
  });
171
 
 
 
 
 
 
172
  document.addEventListener('gradioUpdated', function(event) {
173
  setTimeout(playAssistantAudio, 100);
174
  });
 
165
  }
166
  }
167
 
168
+ // Automatically play the assistant's audio when it's loaded
169
+ const audioOutputObserver = new MutationObserver((mutations) => {
170
+ mutations.forEach((mutation) => {
171
+ if (mutation.type === 'childList') {
172
+ const addedNodes = mutation.addedNodes;
173
+ addedNodes.forEach((node) => {
174
+ if (node.tagName === 'AUDIO') {
175
+ setTimeout(() => {
176
+ node.play();
177
+ }, 100);
178
+ }
179
+ });
180
+ }
181
+ });
182
  });
183
 
184
+ const audioOutputElement = document.querySelector('#audio-output');
185
+ if (audioOutputElement) {
186
+ audioOutputObserver.observe(audioOutputElement, { childList: true, subtree: true });
187
+ }
188
+
189
  document.addEventListener('gradioUpdated', function(event) {
190
  setTimeout(playAssistantAudio, 100);
191
  });