当声音文件位于同一目录中时,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

解决方法

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

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

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...