Python: Stop Google Audio Recording when user click stop button

150 Views Asked by At

Im using Google Speech API

The system shall work as the following:

1- When user click "Start" button, System shall start recording

2- When user click "Stop" button, System shall stop recording and display the result

Her is my "Start" button definition

def Recite():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        audio = r.listen(source)
        try:
            global s
            s = r.recognize_google(audio,language ="ar-AR")

        except sr.UnknownValueError: 
            print("Google Speech Recognition could not understand audio") 
            title4= tk.Label(text ="غير مفهوم ", foreground="red")
            title4.grid(column=0,row=16)
        except sr.RequestError as e: 
            print("Could not request results from Google Speech Recognition service; {0}".format(e))
            title5= tk.Label(text ="حدث خطأ ", foreground="red")
            title5.grid(column=0,row=16) 
    

My question is, how can I have another definition to be called when user want to stop recording and click button "Stop"?

0

There are 0 best solutions below