Reputation: 41
I have a piece of code that plays a sound using the playsound module but the file location gives an error:
import playsound
playsound.playsound('C:\\Users\\nc_ma\\Downloads\\Note1.mp3')
error:
Error 305 for command:
open "C:\Users\nc_ma\Downloads\Note1.mp3"
Cannot specify extra characters after a string enclosed in quotation marks.
Upvotes: 3
Views: 3183
Reputation: 46
Playsound is still working in Python version 3.10.11. For my use case the mp3 files were in a different folder under the parent directory of the py file accessing the mp3. I was able to get the mp3 file path by getting the current py file path [os.path.realpath(file)] then getting the parent [..\] then current directory [.\]
playsound(str(os.path.dirname(os.path.realpath(__file__))) + "\\..\\.\\folder\file.mp3")
Specifying the parent then the rest of the path does not work, so you have to specify current path. For example, this does not work:
playsound(str(os.path.dirname(os.path.realpath(__file__))) + "\\..\\folder\file.mp3")
Upvotes: 0
Reputation: 541
The python package playsound is effectively broken. I made a replacement here:
https://github.com/zackees/playaudio
Which can be installed via:
pip install playaudio
Keep in mind this is a blocking library. So you'll need to wrap it in a thread if you want to want async behavior.
Upvotes: 0
Reputation: 71
I was having a similar issue of Error 305 . Check your playsound version. There is an issue with version 1.3. Downgrading to version 1.2.2 worked for me.
Follow the below steps:
pip uninstall playsound
pip install playsound==1.2.2
Run the same file again. It should work.
Upvotes: 3
Reputation: 46
I had the same problem and I tried another way:
I used os
import os
os.startfile('path\\file.filetype')
and it started working for you:
os.startfile('C:\\Users\\nc_ma\\Downloads\\Note1.mp3')
or
from playsound import playsound
playsound('Path\\File Name.mp3')
Upvotes: 0