当声音文件位于同一目录中时,playsound说找不到文件

时间:2020-09-18 15:12:35

标签: python audio notifications playsound

我的代码是一个自动通知系统。与我的代码一起使用的音频文件与python文件位于同一目录中。但是当我运行代码时,playsound说找不到文件。

#import modules

import schedule
import time
from playsound import playsound

#define functions 
def g_assembly():
    #play sound when function is called
    playsound("trialvoice.mp3")


def greet():
    playsound("trialvoice.mp3")


#initiate schedule
schedule.every().friday.at('15:55').do(g_assembly)
schedule.every().friday.at('15:56').do(greet)

#keep schedule running
while True:
    schedule.run_pending()
    time.sleep(1)

这是下面的错误

Error 275 for command:
open "trialvoice.mp3" alias playsound_0.9746097500934046
Cannot find the specified file.  Make sure the path and filename are correct.

Process finished with exit code 1

1 个答案:

答案 0 :(得分:1)

我面临着同样的问题。 您必须指定Mp3文件的完整路径,并以mp3扩展名结尾的文件名。例如:

ddev poweroff && mkcert -uninstall && sudo rm -rf "$(mkcert -CAROOT)" && mkcert -install

我的mp3文件的名称是“ Song”。但是我必须用文件的完整位置编写“ song.mp3”。 如果文件名是“ song.mp3”,则必须写“ song.mp3.mp3”以及文件的完整位置。