winsound
is a module in Python that enables the sound-playing mechanism in Windows systems. It includes several functions and constants, one of which is the SND_ALIAS
constant.
PlaySound
is a built-in method of the winsound
module, which allows us to play any sound. The syntax of the function is:
PlaySound(sound, flag)
The sound
parameter can be a filename, audio data as a bytes-like object, or None.
The flag
parameter is used to provide a value to interpret the sound.
SND_ALIAS
is one such flag used in the PlaySound
function, which can be interpreted as a control panel sound association name. Following are the basic sounds supported by a Win32 system:
Sound name in PlaySound |
Control panel sound name |
---|---|
‘SystemAsterisk’ | Asterisk |
‘SystemExclamation’ | Exclamation |
‘SystemExit’ | Exit Windows |
‘SystemHand’ | Critical Stop |
‘SystemQuestion’ | Question |
If the sound name is not registered, the system default sound is played unless
SND_NODEFAULT
is specified.
The following piece of code plays the windows exit sound:
import winsound
# Play Windows exit sound.
winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
Free Resources