How to call function when "stop recording" button pressed?

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:

image
is pressed ?

Answered here: How to call function when "stop recording" button pressed ? · gradio-app/gradio · Discussion #4024 · GitHub

That doesn’t work:

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 = [])
        stream_input.stop(stop_streaming)

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

When pressing on “stop recording” the function stop_streaming is not called