playsound says file not found when audio file is in same directory

3.8k Views Asked by At

My code is an auto notification system. The audio file I used with my code s in the same directory as the Python file. But when I run the code, playsound says file not found.

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)

this is the error below:

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

There are 1 best solutions below

0
On

I was facing the same issue. You must specify the complete path of the Mp3 file with name of file ending with mp3 extension. For example:

from playsound import playsound
playsound('G:\\Python\\song.mp3')

The name of my mp3 file here is "Song". But I have to write "song.mp3" with the complete location of the file. If the name of the file is "song.mp3" then you will have to write "song.mp3.mp3" along with the complete location of the file.