Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -88,7 +88,7 @@ def create_demo():
|
|
88 |
|
89 |
with gr.Column(scale=1):
|
90 |
chat_output = gr.Textbox(label="AI Response")
|
91 |
-
audio_output = gr.Audio(label="AI Voice Response")
|
92 |
|
93 |
demo.load(None, js="""
|
94 |
function() {
|
@@ -97,11 +97,26 @@ def create_demo():
|
|
97 |
document.querySelector('button[title="Submit"]').click();
|
98 |
}, 500);
|
99 |
});
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
});
|
106 |
}
|
107 |
""")
|
|
|
88 |
|
89 |
with gr.Column(scale=1):
|
90 |
chat_output = gr.Textbox(label="AI Response")
|
91 |
+
audio_output = gr.Audio(label="AI Voice Response", autoplay=True)
|
92 |
|
93 |
demo.load(None, js="""
|
94 |
function() {
|
|
|
97 |
document.querySelector('button[title="Submit"]').click();
|
98 |
}, 500);
|
99 |
});
|
100 |
+
|
101 |
+
// Function to play the assistant's audio response
|
102 |
+
function playAssistantAudio() {
|
103 |
+
var audioElements = document.querySelectorAll('audio');
|
104 |
+
if (audioElements.length > 1) {
|
105 |
+
var assistantAudio = audioElements[1]; // The second audio element is the assistant's response
|
106 |
+
if (assistantAudio) {
|
107 |
+
assistantAudio.play();
|
108 |
+
}
|
109 |
}
|
110 |
+
}
|
111 |
+
|
112 |
+
// Play assistant's audio when it's loaded
|
113 |
+
document.addEventListener('gradioAudioLoaded', function(event) {
|
114 |
+
playAssistantAudio();
|
115 |
+
});
|
116 |
+
|
117 |
+
// Also try to play the audio when the interface updates
|
118 |
+
document.addEventListener('gradioUpdated', function(event) {
|
119 |
+
setTimeout(playAssistantAudio, 100); // Small delay to ensure audio is ready
|
120 |
});
|
121 |
}
|
122 |
""")
|