pythonspeech-recognition

How to add Hotword Detection in python AI


I am trying to make a python AI using the speech_recognition module, and i want to add a hotword detection feature in the AI, so I tried to make it using speech_recognition module but it didn't work. It listened once after 4 - 5 seconds and started recognizing the things spoken. Therefor if I speak the hotword after the 4-5 second timeframe, it doesn't recognize the hotword.


Solution

  • Use pause_threshold like

    import speech_recognition as sr
    hot_word='Hi'
    r=sr.Recognizer()
    r.pause_threshold=5#This waits for 5 sec after voice ends
    with sr.Microphone() as source:
        text=r.listen(source)
    text=r.recognize_google(text)
    if hot_word in text:
        #do anything like calling a function or reply to it
    

    Thank you
    Have a good day