我在这里尝试再次使用 os 模块,但它无法正常工作,它会抛出错误,我正在用 python 制作桌面助手 AI

问题描述 投票:0回答:0

所以现在我正在用 python 制作一个像 (SIRI) 这样的 AI 助手,所以我只能打开网站并且能够告诉我现在我想在我的桌面上打开文件和播放音乐的时间,我肯定需要操作系统模块但是每当我使用它时,它都会显示错误,就像当我要求它做任何与系统相关的事情时,打开任何涉及操作系统模块的应用程序,它都会接受句子中的单词并抛出错误,如----(EG:-“ OPEN DISCORD") 所以它显示的错误是('open' 不被识别为内部或外部命令、可运行的程序或批处理文件。) 下面我附上代码:--------

import win32com.client as wincom
import speech_recognition as sr
import webbrowser
import os
import openai
import datetime

speak = wincom.Dispatch("SAPI.SpVoice")

def say(text):
    print(f"{text}")

def takeCommand():
    r = sr.Recognizer()
    with  sr.Microphone() as source:
        r.pause_threshold = 0.5            #BY DEFAULT IT IS 0.8 SEC
        audio = r.listen(source)
        try:
            query = r.recognize_google(audio, language="eng-in")
            print(f"User said: {query}")
            return query
        except Exception as e:
            print("Jarvis couldn't hear,please try again speaking")
            speak.Speak("Jarvis couldn't hear,please try again speaking")
            return "Jarvis couldn't hear,please try again speaking"

if __name__ == '__main__':
    print('PyCharm')
    speak.Speak("Hello I am Jarvis AI,how may I help you")
    while True:
        print("Listening.....")
        query = takeCommand()
        sites = [["youtube","https://www.youtube.com"], ["wikipedia", 
"https://www.wikipedia.com"],
        ["google","https://ww.google.com"],]
        for site in sites:
            if f"Open {site[0]}".lower() in query.lower():
                speak.Speak(f"Opening {site[0]} Sir....")
                webbrowser.open(site[1])
            if "the time" in query:
                hour = datetime.datetime.now().strftime("%H")
                min = datetime.datetime.now().strftime("%M")
                speak.Speak(f"Sir  time is{hour} hour {min} minutes")
            if "open discord".lower() in query.lower():
                os.startfile(f"open C:\\Users\\MANAN\\Desktop\\Discord") #HERE IT IS THROWING ERROR

我想在 PC 中打开 discord 或任何其他应用程序,但这个操作系统模块问题没有得到解决

python path artificial-intelligence desktop-application
© www.soinside.com 2019 - 2024. All rights reserved.