speech_recognition icon indicating copy to clipboard operation
speech_recognition copied to clipboard

How to make google speech API keep listening even if user stop talking

Open balnamlah opened this issue 4 years ago • 1 comments

Im using Google Speech API

The system shall work as the following:

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

2- When the user click "Stop" button, the 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) 
    

the issue is, my system stops recognition automatically when the user stops talking how can I stop only if the user does action (Click the "Stop" button)?

balnamlah avatar Nov 04 '20 17:11 balnamlah

Put your function inside a infinite loop.

Im using Google Speech API

The system shall work as the following:

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

2- When the user click "Stop" button, the 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) 
    

the issue is, my system stops recognition automatically when the user stops talking how can I stop only if the user does action (Click the "Stop" button)?

ShevO27 avatar Nov 19 '20 20:11 ShevO27