1

I want to be able to call to a function when the button of "stop recording" is pressed.

I have the following simple code:

import gradio as gr

def handle_streaming(stream_in):
    print(f" Got New Samples")

def stop_streaming():
    print("Streaming has stopped")

if __name__ == "__main__":

    with gr.Blocks(theme=gr.themes.Glass()) as demo:

        stream_input = gr.Audio(source="microphone")
        stream_input.stream(fn      = handle_streaming,
                            inputs  = [stream_input],
                            outputs = [],
                            every   = 1)

    demo.queue().launch(share=False,  debug=False)

How can I call to my function stop_streaming, when the button:

enter image description here is pressed?

user3668129
  • 4,318
  • 6
  • 45
  • 87

1 Answers1

0

Audio objects have stop_recording event listeners, so in your case stream_input.stop_recording(stop_streaming) should work.

For more complicated use cases, you will probably need to call your function after the stop_recording call, e.g. stream_input.stop_recording(lambda: None).then(stop_streaming).