audio - Playing sound from a specific location in Python Tkinter -
goal
to play wav file location d:1.wav, when application started user
research
saw following questions:
how go playing alarm sound in python?
what tried
i tried following lines:
example 1
import winsound winsound.playsound('d:\1.wav',winsound.snd_filename) ##did not work example 2
import winsound winsound.playsound('1.wav',winsound.snd_filename) ##did not work both times got default sound not sound should have played per audio file
also
- when write
winsound.playsound('1.wav',winsound.snd_filename)python check file1.wav? in directory? - why flag
winsound.snd_filenameused for?
specs python 2.7 tkinter 8.5 windows xp sp
please me issue.
change
winsound.playsound('d:\1.wav',winsound.snd_filename) to
winsound.playsound('d:\\1.wav',winsound.snd_filename) to prevent python escaping path:
>>> = '\1.wav' >>> '\x01.wav' winsound.snd_filename
the sound parameter name of wav file. not use snd_alias.
(from winsound docs)
if don't use flag winsound.snd_nodefault, winsound plays default sound if cannot find specified file.
create folder (say d:\test_sounds\) wav file inside, add folder pythonpath variable , try running code again. or (better, if plan distribute code), following same post linked, add code:
import sys if "d:\\my_sound_folder" not in sys.path: sys.path.append("d:\\my_sound_folder") and can call winsound.playsound('1.wav', winsound.snd_filename) since in available paths
Comments
Post a Comment