gradio/demo/stream_audio/run.py
Abubakar Abid 4d58ae79b3
Improvements to State (#2100)
* state

* state fix

* variable -> state

* fix

* added state tests

* formatting

* fix test

* formatting

* fix test

* added tests for bakcward compatibility

* formatting

* config fix

* additional doc

* doc fix

* formatting
2022-08-29 09:53:05 -07:00

20 lines
525 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.State()
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()