Speech recognition: microphone is detected only once, then it's not being detected

I developed a script to recognize speech. The first time I run the script, the mic is detected and the speech is transcribed correctly. But when I try a second time, nothing happens, as if the microphone is not being detected at all.
The script is launched from a streamlit button.
Here is the SR code:

import speech_recognition as sr

r= sr.Recognizer()
def get_audio():
    with sr.Microphone() as source:
        r.pause_threshold=0.5
        audio=r.listen(source)
        said=""


    try:
        print("inside Try")
        said=r.recognize_google(audio, language="fr-FR")
        print(said)
    except sr.UnknownValueError:
        print("Exception: Google speech recogniton could not understand audio")
    except sr.RequestError as e:
        print(f"Could not request results from Google Speech Recognition service: {e}")
    return said

And this is how I call the script from a streamlit button:

if st.button("Click-me to speak"):
        text= get_audio()
        query = st.text_input("Input your prompt here: ", text, key="transcription")
        if query:
            submit = True

Hi,

the if statement is run once. Run it in a loop.

while True:
   # Your if statement code here

What happens if you run the script directly multiple times, instead of via streamlit?

I will try that. it could be that the problem comes from stramlit