Search code examples
pythonartificial-intelligence

I have an error when I run it, how do I fix it?


import speech_recognition
Robot_ear = speech_recognition.Recognizer()
with speech_recognition.Microphone() as mic:
    print("Robot: I'm listening")
    audio = Robot_ear.Listen(mic)

you = Robot_ear.Recognizer_google(audio)
print(you)

And I have an error: Traceback (most recent call last): File "C:\Users\admin\Documents\code\nghe.py", line 5, in audio = Robot_ear.Listen(mic) AttributeError: 'Recognizer' object has no attribute 'Listen'


Solution

  • Here is the updated code:

    import speech_recognition
    Robot_ear = speech_recognition.Recognizer()
    with speech_recognition.Microphone() as mic:
        print("Robot: I'm listening")
        audio = Robot_ear.listen(mic)
    
    you = Robot_ear.recognize_google(audio)
    print(you)
    

    I'll explain your errors,

    1. First go through the documentation before you go to the programming

    2. The errors are:

      a)Use small letter in Listen i.e listen

      b) Use small letter in Recognize.google() i.e recognize.google()