Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

speech-recognition is too slow

Too much time is spent for speech recognition. The recognition takes over 15 minutes to run.

How can I make the speech recognition faster? Here's my code:

def takeCommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        audio = r.listen(source)
    try:
        print("Recognizing...")
        query= r.recognize_google(audio,language= 'en-in')
        print(f"user said: {query}\n")
    except Exception as e:
        speak("Miss stark couldn't recognize what you said, speak once more.")
        print("Miss stark couldn't recognize what you said, speak once more.")
        query=None

    return query
like image 404
arpita halder Avatar asked Oct 18 '25 04:10

arpita halder


1 Answers

You can use this code more frequently using these lines added to your.

  def takeCommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        r.pause_threshold = 1
        r.adjust_for_ambient_noise(source)
        print("Listening...")
        audio = r.listen(source)
    try:
        print("Recognizing...")
        query= r.recognize_google(audio,language= 'en-in')
        print(f"user said: {query}\n")
    except Exception as e:
        speak("Miss stark couldn't recognize what you said, speak once more.")
        print("Miss stark couldn't recognize what you said, speak once more.")
        return None
    return query

And if this not works check your internet connection speed, because SpeechRecognition works through internet connection.

like image 108
Raghav Avatar answered Oct 19 '25 20:10

Raghav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!