python - Error when I try to play a sound -
i trying make alarm clock sort of thing when try , run thing using error:
file "c:\python27\salty.py", line 2, in <module> winsound.playsound('siren.wav') typeerror: playsound() takes 2 arguments (1 given) here code running. import winsound winsound.playsound('siren.wav')
i know simple fix late. thank help!
winsound.playsound takes two parameters: sound , flags. sound
may filename, audio data string, or
none
(from docs), while flags bitwise-or'd combination of winsound.snd_filename (the sound parameter path .wav file), winsound.snd_alias (the sound parameter name builtin windows sound, see docs), winsound.snd_loop (play sound in loop), winsound.snd_memory (the sound parameter memory image of .wav file), winsound.snd_purge (stop playing instances of specified sound, not supported on modern windows), winsound.snd_async (return immediately, allowing sounds play asynchronously), winsound.snd_nodefault (do not play default sound if sound cannot found), winsound.snd_nostop (do not interrupt other sounds playing) , winsound.snd_nowait (return if sound driver busy)
what want winsound.snd_filename flag:
import winsound winsound.playsound('siren.wav', winsound.snd_filename) or, function:
import winsound def playsiren(): winsound.playsound('siren.wav', winsound.snd_filename) edited add:
it may necessary give whole path (e.g. 'c:\\whatever\\siren.wav') instead of file name (as discussed in comments).
Comments
Post a Comment