python - 在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'
谢谢...
解决方案
推荐阅读
- android - 在午夜增加共享偏好的数量
- ansible - 从两个数组 Ansible 中获取差异
- vue.js - Vuetify - 清除 v-text-field 时如何触发方法
- html - 均匀间隔图标,无论它们是否有通知徽章
- ios - HTTP 加载失败(错误代码:-1005 [4:-4]) - 但不是 Alamofire
- firebase - 2个日期之间的firebase实时数据库查询日期不匹配任何内容
- python - 使用 python 子进程从无限运行的程序中读取
- node.js - 如何使用 Nginx 通过 express 路由器加载页面
- python - 用户提交表单后,Django视图不呈现数据
- java - 我可以使用 spring boot 覆盖遗留生成代码的 jdbc 目录吗?