首页 > 解决方案 > 在Python中获取attributeError

问题描述

好吧,嘿,我只是编码和 Python 的初学者......所以,希望你理解并帮助我。

我在运行我的代码时遇到错误,我试图修复它但一切都失败了

这是代码:

import wikipedia
import speech_recognition as sr


engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)


def speak(audio):
    # it speak given audio
    engine.say(audio)
    print(audio)
    engine.runAndWait()

def takeCommand():
    # it takes microphone input and returns the input as string output
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listning....")
        r.pause_threshold = 0.5
        audio = r.listen(source)

    try:
        print("Recognizing...")
        query = r.recognize_google(audio, language='eng-in').lower
        print(f"User said: {query}")
        
    except Exception as e:
        print(f"Sir it seems like there is an error !!! The error is {e}")
        print("Say that again please...")
        return "None"
    return query

if __name__ == "__main__":
    while True:

        query = takeCommand().lower()

        if 'wikipedia' in query:
            speak("searching Wikipedia")
            query = query.replace("wikipedia", "")
            results = wikipedia.summary(query, sentences=2)
            speak("According to Wikipedia")
            speak(results)

这是错误:

Listning....
Recognizing...
User said: <built-in method lower of str object at 0x0000026CB42BED50>
Traceback (most recent call last):
  File "c:\Users\Rahul\Documents\Codes\Project A.I\Test1.py", line 52, in <module>
    query = takeCommand().lower()
AttributeError: 'builtin_function_or_method' object has no attribute 'lower'

谢谢...

标签: pythonattributeerror

解决方案


推荐阅读