我创建了一个虚拟助手,一切正常,但现在我安装了一个 api,我的音乐功能无法获取位置

I created a virtual assistant, everything was fine but now after I installed an api, my music function is not able to get the location

我创建了一个虚拟助手,之前播放音乐,安装api后"zolframalpha",播放音乐出错我附上错误代码

错误是:

line 1 :-----File "C:\Users\Hari Prakash\Desktop\siri\main.py", line 62, in playMusic      os.startfile(location+musics[0]) 

line2:--------- FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\Users\Hari Prakash\Desktop\siri\musics//wolframalpha.cpython-37.pyc' 
def playMusic(self):
    self.speak('Playing Music Please Wait')
    musics = [x for x in os.walk(os.getcwd())][-1][-1]
    shuffle(musics)
    location = os.path.join(
        os.getcwd(),
        "musics//"  
    )
    os.startfile(location+musics[0])
    print(musics)
    self.main()

musics = [x for x in os.walk(os.getcwd())][-1][-1]

获取当前工作目录最后一个子目录中的文件列表

假设您的音乐位于当前工作目录的 "musics" 文件夹中,您可以像这样重新排序代码并更改 musics =

def playMusic(self):
    self.speak('Playing Music Please Wait')
    location = os.path.join(
        os.getcwd(),
        "musics//"  
    )
    # get all files in musics location
    musics = [x for x in os.listdir(location) if os.path.isfile(location + x)]
    shuffle(musics)

    os.startfile(location+musics[0])
    print(musics)
    self.main()