Desamax1
Desamax1

Reputation: 59

Python speech recognition very slow

I am currently developing a smart assistant program (basically it is just listening to what the user says and based on that does something with the code). It was working fine up until today, when I switched to my laptop. The program does not print out any errors, but it also doesn't print out what I said. I'm using the Python Speech Recognition library version 3.8.1. Does anybody know of an alternative for this library? If yes, please try to explain how I would use it 'on the fly' (without first recording the file and then sending it to the server, more like real-time speech).

EDIT: I forgot to say it in the post, I'm using Python 3.

EDIT: Here's the code:

#!/usr/bin/env python3

import speech_recognition as sr


global x


def speech():

    try:
        with sr.Microphone() as source:
            global x
            r = sr.Recognizer()
            audio = r.listen(source)
            x = r.recognize_google(audio)
    except sr.UnknownValueError:
        print("No clue what you said, listening again... \n")
        speech()


if __name__ == '__main__':
    print('Listening and printing what I heard: \n')
    speech()
    print(x)

Upvotes: 3

Views: 7918

Answers (2)

Just_A_Coder
Just_A_Coder

Reputation: 43

Another reason could be that your mic levels are either too high or too low, in both the cases the speech_recognition would get either too less audio or too much audio to work with. Take a look at that in your system settings. It helped me, hope it helps you.

Upvotes: 0

Desamax1
Desamax1

Reputation: 59

I found that the problem was in the laptop's microphone. The speech recognition worked fine after I plugged in my Blue Snowball. I forced the program to use the Blue Snowball by going into pavucontrol and selecting the Blue Snowball under the recording tab.

Upvotes: 3

Related Questions