创建Jarvis AI时出现错误,对象不可调用等

错误代码 👈这是图片 这是我的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("正在监听...")                    r.pause_threshold = 4                    r.energy_threshold = 300                    audio = r.listen(source, 0, 4)                try:                    print("正在理解...")                    query = r.recognize_google(audio, language='en-us')                    print(f"你说的是: {query}\n")                except Exception as e:                    print("请再说一遍")                    return "None"                return query            # 开始...............................................................................................................            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("早上好,先生,你好吗?")                        elif 12 < hour <= 18:                            speak("下午好,先生,你好吗?")                        else:                            speak("晚上好,先生,你好吗?")                    while True:                        query = takeCommand().lower()                        if "go to sleep david" in query:                            speak("好的,再见,记得需要任何帮助时只要说,wake up david")                            break                        elif "I'm good how are you" in query:                            speak("我也很不错,今天我能帮你什么吗?")                        elif "thank you" in query:                            speak("不客气,先生")            # 网络浏览器搜索..................................................................................................                        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("这是我找到的")                                try:                                    pywhatkit.search(query)                                    result = googleScrap.summary(query, 1)                                    speak(result)                                except:                                    speak("抱歉,没有找到相关信息")                query = query.replace("jarvis", "")                query = query.replace("google search", "")                query = query.replace("google", "")                speak("这是我在谷歌上找到的")                try:                    pywhatkit.search(query)                    result = googleScrap.summary(query, 1)                    speak(result)                finally:                    speak("没有可播报的输出")            def searchYoutube(query):                if "youtube" in query:                    speak("这是我为你的搜索找到的!")                    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("完成,先生")            def searchWikipedia(query):                if "wikipedia" in query:                    speak("正在从维基百科搜索....")                    query = query.replace("wikipedia", "")                    query = query.replace("search wikipedia", "")                    query = query.replace("jarvis", "")                    results = wikipedia.summary(query,sentences=2)                    speak("根据维基百科..")                    print(results)                    speak(results)

这些是我得到的错误代码

第51行,query = takeCommand().lower()

第25行,takeCommandaudio = r.listen(source, 0, 4)

第652行,listenbuffer = source.stream.read(source.CHUNK)

第161行,readreturn self.pyaudio_stream.read(size, exception_on_overflow=False)

第608行,readreturn pa.read_stream(self._stream, num_frames, exception_on_overflow)

KeyboardInterrupt

调用ctypes回调函数时忽略的异常: <function catch_errors..call_with_this at 0x000001E3FA726560>Traceback (most recent call last):

第97行,call_with_this

第1734行,isEnabledForTypeError: ‘NoneType’ 对象不可调用

这些是我安装的模块:

import datetimeimport webbrowserimport pyttsx3import pywhatkitimport speech_recognitionimport wikipedia


回答:

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注