Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
from gtts import gTTS
|
| 3 |
import os
|
| 4 |
import speech_recognition as sr
|
|
|
|
| 5 |
|
| 6 |
# Menu for the restaurant
|
| 7 |
menu = {
|
|
@@ -100,7 +101,7 @@ def process_order(audio_file_path):
|
|
| 100 |
audio_response_path = speak_and_save(response)
|
| 101 |
return response, audio_response_path
|
| 102 |
|
| 103 |
-
# Gradio Interface with Auto-
|
| 104 |
def create_interface():
|
| 105 |
with gr.Blocks() as app:
|
| 106 |
gr.Markdown("## Restaurant Voice Assistant")
|
|
@@ -110,14 +111,16 @@ def create_interface():
|
|
| 110 |
text_response = gr.Textbox(label="Text Response")
|
| 111 |
audio_response = gr.Audio(label="Audio Response", interactive=False)
|
| 112 |
|
| 113 |
-
# Add JavaScript for auto-playing audio
|
| 114 |
gr.HTML("""
|
| 115 |
<script>
|
| 116 |
document.addEventListener("change", function() {
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
| 121 |
});
|
| 122 |
</script>
|
| 123 |
""")
|
|
|
|
| 2 |
from gtts import gTTS
|
| 3 |
import os
|
| 4 |
import speech_recognition as sr
|
| 5 |
+
import time
|
| 6 |
|
| 7 |
# Menu for the restaurant
|
| 8 |
menu = {
|
|
|
|
| 101 |
audio_response_path = speak_and_save(response)
|
| 102 |
return response, audio_response_path
|
| 103 |
|
| 104 |
+
# Gradio Interface with Auto-Play After 3 Seconds
|
| 105 |
def create_interface():
|
| 106 |
with gr.Blocks() as app:
|
| 107 |
gr.Markdown("## Restaurant Voice Assistant")
|
|
|
|
| 111 |
text_response = gr.Textbox(label="Text Response")
|
| 112 |
audio_response = gr.Audio(label="Audio Response", interactive=False)
|
| 113 |
|
| 114 |
+
# Add JavaScript for auto-playing audio 3 seconds after response
|
| 115 |
gr.HTML("""
|
| 116 |
<script>
|
| 117 |
document.addEventListener("change", function() {
|
| 118 |
+
setTimeout(function() {
|
| 119 |
+
const audioPlayer = document.querySelector("audio");
|
| 120 |
+
if (audioPlayer) {
|
| 121 |
+
audioPlayer.play();
|
| 122 |
+
}
|
| 123 |
+
}, 3000); // Delay of 3 seconds
|
| 124 |
});
|
| 125 |
</script>
|
| 126 |
""")
|