Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -108,7 +108,7 @@ def create_demo():
|
|
108 |
gr.Markdown(
|
109 |
"""
|
110 |
# 🗣️ AI Voice Assistant
|
111 |
-
Welcome to your personal voice assistant! Simply record your voice, and I will respond with both text and speech. Powered by advanced AI models.
|
112 |
"""
|
113 |
)
|
114 |
|
@@ -139,13 +139,32 @@ def create_demo():
|
|
139 |
audio_input.change(process_audio, inputs=[audio_input, voice_volume], outputs=[chat_output, audio_output])
|
140 |
clear_button.click(lambda: (None, None), None, [chat_output, audio_output])
|
141 |
|
142 |
-
# JavaScript to handle autoplay
|
143 |
demo.load(None, js="""
|
144 |
function() {
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
});
|
150 |
|
151 |
function playAssistantAudio() {
|
|
|
108 |
gr.Markdown(
|
109 |
"""
|
110 |
# 🗣️ AI Voice Assistant
|
111 |
+
Welcome to your personal voice assistant! Simply record your voice, and I will respond with both text and speech. The assistant will automatically start listening after playing its response. Powered by advanced AI models.
|
112 |
"""
|
113 |
)
|
114 |
|
|
|
139 |
audio_input.change(process_audio, inputs=[audio_input, voice_volume], outputs=[chat_output, audio_output])
|
140 |
clear_button.click(lambda: (None, None), None, [chat_output, audio_output])
|
141 |
|
142 |
+
# JavaScript to handle autoplay, automatic submission, and auto-listen
|
143 |
demo.load(None, js="""
|
144 |
function() {
|
145 |
+
var recordButton;
|
146 |
+
|
147 |
+
function findRecordButton() {
|
148 |
+
var buttons = document.querySelectorAll('button');
|
149 |
+
for (var i = 0; i < buttons.length; i++) {
|
150 |
+
if (buttons[i].textContent.includes('Record from microphone')) {
|
151 |
+
return buttons[i];
|
152 |
+
}
|
153 |
+
}
|
154 |
+
return null;
|
155 |
+
}
|
156 |
+
|
157 |
+
function startListening() {
|
158 |
+
if (!recordButton) {
|
159 |
+
recordButton = findRecordButton();
|
160 |
+
}
|
161 |
+
if (recordButton) {
|
162 |
+
recordButton.click();
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
document.querySelector("audio").addEventListener("ended", function() {
|
167 |
+
setTimeout(startListening, 500);
|
168 |
});
|
169 |
|
170 |
function playAssistantAudio() {
|