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

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-call-function-when-stop-recording-button-pressed%2F38287%3E%5C
**Category:** 🔒 Gradio\
**Created:** [May 1, 2023, 11:14am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-call-function-when-stop-recording-button-pressed%2F38287 "2023-05-01T11:14:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![laro1](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@laro1](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flaro1)%5C
**Post date:** [May 1, 2023, 11:14am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-call-function-when-stop-recording-button-pressed%2F38287%2F1 "2023-05-01T11:14:31Z")

</div>

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

I have the following simple code:

```auto
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](https://us1.discourse-cdn.com/hellohellohello/original/2X/2/2f2117a183bb1b7a616928d390ddb017e5773a6d.png)  
is pressed ?

---

<div class="post-metadata">

**Author:** ![freddyaboulton](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/freddyaboulton/32/32732_2.png) [@freddyaboulton](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffreddyaboulton)%5C
**Post date:** [May 1, 2023, 2:25pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-call-function-when-stop-recording-button-pressed%2F38287%2F2 "2023-05-01T14:25:05Z")

</div>

Answered here: [How to call function when "stop recording" button pressed ? · gradio-app/gradio · Discussion #4024 · GitHub](https://github.com/gradio-app/gradio/discussions/4024)

---

<div class="post-metadata">

**Author:** ![laro1](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@laro1](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flaro1)%5C
**Post date:** [May 1, 2023, 2:41pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-call-function-when-stop-recording-button-pressed%2F38287%2F3 "2023-05-01T14:41:19Z")

</div>

That doesn’t work:

```auto
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
