Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
-
import time
|
4 |
|
5 |
-
def
|
6 |
-
time.sleep(1)
|
7 |
if audio is None:
|
8 |
-
return
|
9 |
-
|
10 |
-
|
|
|
11 |
else:
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
with gr.Blocks() as demo:
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
19 |
clear = gr.Button("Clear")
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
if __name__ == "__main__":
|
25 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
|
|
3 |
|
4 |
+
def process_audio(audio, state):
|
|
|
5 |
if audio is None:
|
6 |
+
return None, state
|
7 |
+
|
8 |
+
if state is None:
|
9 |
+
state = audio
|
10 |
else:
|
11 |
+
# Concatenate only the new audio data
|
12 |
+
state = (state[0], np.concatenate((state[1], audio[1])))
|
13 |
+
|
14 |
+
# Return only the new chunk for playback
|
15 |
+
return audio, state
|
16 |
|
17 |
with gr.Blocks() as demo:
|
18 |
+
audio_input = gr.Audio(source="microphone", streaming=True)
|
19 |
+
audio_output = gr.Audio(streaming=True)
|
20 |
+
state = gr.State()
|
21 |
+
|
22 |
clear = gr.Button("Clear")
|
23 |
+
|
24 |
+
audio_input.stream(
|
25 |
+
process_audio,
|
26 |
+
inputs=[audio_input, state],
|
27 |
+
outputs=[audio_output, state],
|
28 |
+
show_progress=False
|
29 |
+
)
|
30 |
+
|
31 |
+
clear.click(lambda: (None, None), outputs=[audio_output, state])
|
32 |
|
33 |
if __name__ == "__main__":
|
34 |
+
demo.launch()
|