0

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
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Michael I.
  • 9
  • 1
  • 4
  • What do you run exactly to raise the error? Here in this piece of code you don't call `g_assembly` or `greet` functions. Also, are you located in another folder when running the program? – Adrien Pavao Sep 18 '20 at 15:19
  • g_assembly and greet functions are called in the schedule block. i did call them. also i am located in the very same folder. my source file and the audio file i want to play. are both in the same folder. – Michael I. Sep 18 '20 at 15:38
  • Are you running the code under Windows? – Adrien Pavao Sep 21 '20 at 17:05
  • Yes. I'm using a windows 10 – Michael I. Sep 22 '20 at 18:58
  • Ok then sorry I can't help you. It may be something related with how Windows interpret path. Maybe you can try to use an absolute path (instead of relative path). – Adrien Pavao Sep 23 '20 at 23:09
  • You did your best thank you. I found a way around it using the schedule module – Michael I. Oct 07 '20 at 05:45

1 Answers1

2

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.