Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
|
|
3 |
|
4 |
-
def
|
|
|
5 |
if audio is None:
|
6 |
-
return
|
7 |
-
|
8 |
-
|
9 |
-
state = audio
|
10 |
else:
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
# Return only the new chunk for playback
|
15 |
-
return audio, state
|
16 |
|
17 |
with gr.Blocks() as demo:
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
clear = gr.Button("Clear")
|
23 |
-
|
24 |
-
|
25 |
-
|
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()
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
+
import time
|
4 |
|
5 |
+
def add_to_stream(audio, instream):
|
6 |
+
time.sleep(1)
|
7 |
if audio is None:
|
8 |
+
return gr.update(), instream
|
9 |
+
if instream is None:
|
10 |
+
ret = audio
|
|
|
11 |
else:
|
12 |
+
ret = (audio[0], np.concatenate((instream[1], audio[1])))
|
13 |
+
return ret, ret
|
|
|
|
|
|
|
14 |
|
15 |
with gr.Blocks() as demo:
|
16 |
+
inp = gr.Audio(source="microphone", streaming=True) # Enable streaming mode
|
17 |
+
out = gr.Audio(streaming=True) # Enable streaming output
|
18 |
+
stream = gr.State()
|
|
|
19 |
clear = gr.Button("Clear")
|
20 |
+
|
21 |
+
inp.stream(add_to_stream, [inp, stream], [out, stream])
|
22 |
+
clear.click(lambda: [None, None, None], None, [inp, out, stream])
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
if __name__ == "__main__":
|
25 |
+
demo.launch()
|