gradio/demo/stream_audio/run.py
aliabid94 2a93225952
Create Streamables (#1279)
* changes

* fix

* fix for vars too

* changes

* fix tests

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2022-05-16 11:51:09 -07:00

20 lines
528 B
Python

import gradio as gr
import numpy as np
with gr.Blocks() as demo:
inp = gr.Audio(source="microphone")
out = gr.Audio()
stream = gr.Variable()
def add_to_stream(audio, instream):
if audio is None:
return gr.update(), instream
if instream is None:
ret = audio
else:
ret = (audio[0], np.concatenate((instream[1], audio[1])))
return ret, ret
inp.stream(add_to_stream, [inp, stream], [out, stream])
if __name__ == "__main__":
demo.launch()