创建jarvis ai时出错,对象不可调用等
Error when creating jarvis ai, object is not callable, etc
Error Code这是图片这是我的ai代码
import datetime
import webbrowser
import pyttsx3
import pywhatkit
import speech_recognition
import wikipedia
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id)
engine.setProperty("rate", 150)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
print("Listening...")
r.pause_threshold = 4
r.energy_threshold = 300
audio = r.listen(source, 0, 4)
try:
print("Understanding...")
query = r.recognize_google(audio, language='en-us')
print(f"You said: {query}\n")
except Exception as e:
print("Say that again")
return "None"
return query
# Starting...............................................................................................................
if __name__ == "__main__":
while True:
query = takeCommand().lower()
if "wake up David" in query:
hour = int(datetime.datetime.now().hour)
if 0 <= hour <= 12:
speak("Good Morning sir, how are you?")
elif 12 < hour <= 18:
speak("Good Afternoon sir, how are you?")
else:
speak("Good Evening sir, how are you?")
while True:
query = takeCommand().lower()
if "go to sleep david" in query:
speak("Ok, See you, Remember if you need anything just say, wake up david")
break
elif "I'm good how are you" in query:
speak("I am also good, how may I help you today?")
elif "thank you" in query:
speak("You are welcome sir")
# Web browser searching..................................................................................................
def searchGoogle(query):
if "google" in query:
import wikipedia as googleScrap
query = query.replace("david", "")
query = query.replace("google search", "")
query = query.replace("google", "")
speak("This is what I found")
try:
pywhatkit.search(query)
result = googleScrap.summary(query, 1)
speak(result)
except:
speak("Did not find anything about that, sorry")
query = query.replace("jarvis", "")
query = query.replace("google search", "")
query = query.replace("google", "")
speak("This is what I found on google")
try:
pywhatkit.search(query)
result = googleScrap.summary(query, 1)
speak(result)
finally:
speak("No speakable output available")
def searchYoutube(query):
if "youtube" in query:
speak("This is what I found for your search!")
query = query.replace("youtube search", "")
query = query.replace("youtube", "")
query = query.replace("jarvis", "")
web = "https://www.youtube.com/results?search_query=" + query
webbrowser.open(web)
pywhatkit.playonyt(query)
speak("Done, Sir")
def searchWikipedia(query):
if "wikipedia" in query:
speak("Searching from wikipedia....")
query = query.replace("wikipedia", "")
query = query.replace("search wikipedia", "")
query = query.replace("jarvis", "")
results = wikipedia.summary(query,sentences=2)
speak("According to wikipedia..")
print(results)
speak(results)
这些是我得到的错误代码
第 51 行,在
query = takeCommand().lower()
第 25 行,在 takeCommand 中
音频 = r.listen(来源, 0, 4)
第652行,在听
缓冲区 = source.stream.read(source.CHUNK)
第 161 行,已读
return self.pyaudio_stream.read(大小,exception_on_overflow=假)
第608行,已读
return pa.read_stream(self._stream, num_frames, exception_on_overflow)
键盘中断
调用 ctypes 回调函数时忽略异常:
回溯(最近调用最后):
第 97 行,在 call_with_this
第 1734 行,在 isEnabledFor
类型错误:'NoneType' 对象不可调用
这些是我安装的模块:
导入日期时间
导入网络浏览器
导入pyttsx3
导入pywhatkit
进口 speech_recognition
导入维基百科
将您的 takeCommand()
函数替换为:
def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
speech_recognition.Recognizer().adjust_for_ambient_noise(source, duration=0.2)
print("Listening...")
audio = r.listen(source)
try:
query = r.recognize_google(audio, language='en-in')
print(f"user said:{query}\n")
except Exception as e:
return "None"
return query
除此之外,您的代码和网络抓取功能没有其他错误。你实际上并没有给他们打电话
更新
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id)
engine.setProperty("rate", 150)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
print("Listening...")
r.pause_threshold = 4
r.energy_threshold = 300
audio = r.listen(source, 0, 4)
try:
print("Understanding...")
query = r.recognize_google(audio, language='en-us')
print(f"You said: {query}\n")
except Exception as e:
print("Say that again")
return "None"
return query
def searchGoogle(query):
import wikipedia as googleScrap
speak("This is what I found")
try:
pywhatkit.search(query)
result = googleScrap.summary(query, 1)
speak(result)
except:
speak("Did not find anything about that, sorry")
def searchYoutube(query):
web = "https://www.youtube.com/results?search_query=" + query
webbrowser.open(web)
pywhatkit.playonyt(query)
speak("Done, Sir")
def searchWikipedia(query):
results = wikipedia.summary(query,sentences=2)
speak("According to wikipedia..")
print(results)
speak(results)
# Starting...............................................................................................................
if __name__ == "__main__":
while True:
query = takeCommand().lower()
if "wake up David" in query:
hour = int(datetime.datetime.now().hour)
if 0 <= hour <= 12:
speak("Good Morning sir, how are you?")
elif 12 < hour <= 18:
speak("Good Afternoon sir, how are you?")
else:
speak("Good Evening sir, how are you?")
while True:
query = takeCommand().lower()
if "go to sleep david" in query:
speak("Ok, See you, Remember if you need anything just say, wake up david")
break
elif "I'm good how are you" in query:
speak("I am also good, how may I help you today?")
elif "thank you" in query:
speak("You are welcome sir")
elif "wikipedia" in query:
speak("Searching from wikipedia....")
query = query.replace("wikipedia", "")
query = query.replace("search wikipedia", "")
query = query.replace("jarvis", "")
searchWikipedia(query)
elif "youtube" in query:
speak("This is what I found for your search!")
query = query.replace("youtube search", "")
query = query.replace("youtube", "")
query = query.replace("jarvis", "")
searchYoutube(query)
elif "google" in query:
query = query.replace("david", "")
query = query.replace("google search", "")
query = query.replace("google", "")
searchGoogle(query)
Error Code这是图片这是我的ai代码
import datetime
import webbrowser
import pyttsx3
import pywhatkit
import speech_recognition
import wikipedia
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id)
engine.setProperty("rate", 150)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
print("Listening...")
r.pause_threshold = 4
r.energy_threshold = 300
audio = r.listen(source, 0, 4)
try:
print("Understanding...")
query = r.recognize_google(audio, language='en-us')
print(f"You said: {query}\n")
except Exception as e:
print("Say that again")
return "None"
return query
# Starting...............................................................................................................
if __name__ == "__main__":
while True:
query = takeCommand().lower()
if "wake up David" in query:
hour = int(datetime.datetime.now().hour)
if 0 <= hour <= 12:
speak("Good Morning sir, how are you?")
elif 12 < hour <= 18:
speak("Good Afternoon sir, how are you?")
else:
speak("Good Evening sir, how are you?")
while True:
query = takeCommand().lower()
if "go to sleep david" in query:
speak("Ok, See you, Remember if you need anything just say, wake up david")
break
elif "I'm good how are you" in query:
speak("I am also good, how may I help you today?")
elif "thank you" in query:
speak("You are welcome sir")
# Web browser searching..................................................................................................
def searchGoogle(query):
if "google" in query:
import wikipedia as googleScrap
query = query.replace("david", "")
query = query.replace("google search", "")
query = query.replace("google", "")
speak("This is what I found")
try:
pywhatkit.search(query)
result = googleScrap.summary(query, 1)
speak(result)
except:
speak("Did not find anything about that, sorry")
query = query.replace("jarvis", "")
query = query.replace("google search", "")
query = query.replace("google", "")
speak("This is what I found on google")
try:
pywhatkit.search(query)
result = googleScrap.summary(query, 1)
speak(result)
finally:
speak("No speakable output available")
def searchYoutube(query):
if "youtube" in query:
speak("This is what I found for your search!")
query = query.replace("youtube search", "")
query = query.replace("youtube", "")
query = query.replace("jarvis", "")
web = "https://www.youtube.com/results?search_query=" + query
webbrowser.open(web)
pywhatkit.playonyt(query)
speak("Done, Sir")
def searchWikipedia(query):
if "wikipedia" in query:
speak("Searching from wikipedia....")
query = query.replace("wikipedia", "")
query = query.replace("search wikipedia", "")
query = query.replace("jarvis", "")
results = wikipedia.summary(query,sentences=2)
speak("According to wikipedia..")
print(results)
speak(results)
这些是我得到的错误代码
第 51 行,在 query = takeCommand().lower()
第 25 行,在 takeCommand 中 音频 = r.listen(来源, 0, 4)
第652行,在听 缓冲区 = source.stream.read(source.CHUNK)
第 161 行,已读 return self.pyaudio_stream.read(大小,exception_on_overflow=假)
第608行,已读 return pa.read_stream(self._stream, num_frames, exception_on_overflow)
键盘中断
调用 ctypes 回调函数时忽略异常:
第 97 行,在 call_with_this
第 1734 行,在 isEnabledFor 类型错误:'NoneType' 对象不可调用
这些是我安装的模块:
导入日期时间 导入网络浏览器 导入pyttsx3 导入pywhatkit 进口 speech_recognition 导入维基百科
将您的 takeCommand()
函数替换为:
def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
speech_recognition.Recognizer().adjust_for_ambient_noise(source, duration=0.2)
print("Listening...")
audio = r.listen(source)
try:
query = r.recognize_google(audio, language='en-in')
print(f"user said:{query}\n")
except Exception as e:
return "None"
return query
除此之外,您的代码和网络抓取功能没有其他错误。你实际上并没有给他们打电话
更新
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id)
engine.setProperty("rate", 150)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
print("Listening...")
r.pause_threshold = 4
r.energy_threshold = 300
audio = r.listen(source, 0, 4)
try:
print("Understanding...")
query = r.recognize_google(audio, language='en-us')
print(f"You said: {query}\n")
except Exception as e:
print("Say that again")
return "None"
return query
def searchGoogle(query):
import wikipedia as googleScrap
speak("This is what I found")
try:
pywhatkit.search(query)
result = googleScrap.summary(query, 1)
speak(result)
except:
speak("Did not find anything about that, sorry")
def searchYoutube(query):
web = "https://www.youtube.com/results?search_query=" + query
webbrowser.open(web)
pywhatkit.playonyt(query)
speak("Done, Sir")
def searchWikipedia(query):
results = wikipedia.summary(query,sentences=2)
speak("According to wikipedia..")
print(results)
speak(results)
# Starting...............................................................................................................
if __name__ == "__main__":
while True:
query = takeCommand().lower()
if "wake up David" in query:
hour = int(datetime.datetime.now().hour)
if 0 <= hour <= 12:
speak("Good Morning sir, how are you?")
elif 12 < hour <= 18:
speak("Good Afternoon sir, how are you?")
else:
speak("Good Evening sir, how are you?")
while True:
query = takeCommand().lower()
if "go to sleep david" in query:
speak("Ok, See you, Remember if you need anything just say, wake up david")
break
elif "I'm good how are you" in query:
speak("I am also good, how may I help you today?")
elif "thank you" in query:
speak("You are welcome sir")
elif "wikipedia" in query:
speak("Searching from wikipedia....")
query = query.replace("wikipedia", "")
query = query.replace("search wikipedia", "")
query = query.replace("jarvis", "")
searchWikipedia(query)
elif "youtube" in query:
speak("This is what I found for your search!")
query = query.replace("youtube search", "")
query = query.replace("youtube", "")
query = query.replace("jarvis", "")
searchYoutube(query)
elif "google" in query:
query = query.replace("david", "")
query = query.replace("google search", "")
query = query.replace("google", "")
searchGoogle(query)