Python winsound basic introduction

Python winsound basic introduction

What is winsound?

The winsound is a python module which  provides access to the basic sound-playing machinery provided by Windows platforms. It includes functions and several constants.

the purpose of introducing to you the winsound module  the task of generating or playing sound or a sound file.

The winsound module is defined only for execution on a Windows Platform, hence the name WINsound


the winsound module is a builtin, there is no need for you to install it prior to executing it.
The basic action would be to import it by 

import winsound


winsound.Beep( )

This function is used to generate a ‘Beep’ sound. However, the user is required to input the frequency 

 value and the duration of the sound (these are parameters that shall be passed while calling the function).

Note: The frequency must be in the range 37 through 32,767 hertz.


import winsound 
# frequency is set
freq = 400
# duration is set to 100 milliseconds             
dur = 100
winsound.Beep(freq, dur)
system will produce a ‘Beep’ sound with the given frequency 
for the given duration of time.


It has two parameters first sound and otherone is flag. The sound parameter may be a filename, a system sound alias, audio data as a bytes-like object, or none .Its interpretation depends on the value of flags, which can be a bitwise ORed combination of the constants described below. If the sound parameter is None, any currently playing waveform sound is stopped. If the system indicates an error, RuntimeError is raised.

Flags and their description

SND_FILENAMEThe sound parameter is the name of a WAV file.
SND_LOOPPlay the sound repeatedly
SND_MEMORYThe sound parameter to PlaySound() is a memory image of a WAV file, as a bytes-like object.
SND_ASYNCReturn immediately, allowing sounds to play asynchronously.
SND_NODEFAULTIf the specified sound cannot be found, do not play the system default sound.

SND_NOSTOP Do not interrupt sounds currently playing.


import winsound print("Playing the file 'Police siren.wav'") # winsound.PlaySound('filename', flag) winsound.PlaySound('mixkit-police-siren-us-1643.wav', winsound.SND_FILENAME)


The respective audio file named 'mixkit-police-siren-us-1643.wav' is executed.

Here, mixkit-police-siren-us-1643 is .wav formate file name
and SND_FILENAME is flag name

More Articles of Anmol Agrawal:

Name Views Likes
Python Pendulum Why to use Pendulum 161 0
Python Pendulum Limitations in DJANGO 240 0
Python Pendulum Limitations in MYSQLCLIENT 160 0
Python Pendulum Limitations in SQLITE3 171 0
Python Pendulum Testing 2 165 0
Python Pendulum Testing 198 0
Python Pendulum Range 199 0
Python Pendulum Period 3 172 0
Python Pendulum Period 2 165 0
Python Pendulum Period 166 0
Python Pendulum Properties and Duration Methods 2 172 0
Python Pendulum Properties and Duration Methods 170 0
Python Pendulum Instantiation 169 0
Python Pendulum Duration 157 0
Python Pendulum TImezone usage 2 162 0
Python Pendulum Timezone usage 178 0
Python Pendulum Switching Timezones 160 0
Python Pendulum Shifting Time to Transition 178 0
Python Pendulum Normalization 177 0
Python Pendulum Modifiers 2 178 0
Python Pendulum Modifiers 174 0
Python Pendulum Difference for Humans 2 202 0
Python Pendulum Difference for Humans 196 0
Python Pendulum Difference 226 0
Python pendulum Substraction 189 0
Pyhton pendulum Addition 192 0
Python pendulum Comapaison part 2 197 0
Python Pendulum Comparison 200 0
Python Pendulum Localized Formats and Escaping characteristics 182 0
Python pendulum Tokens 181 0
Python pendulum Formatter 190 0
Python pendulum Common Formats 189 0
Python pendulum String Formatting 199 0
Python pendulum Fluent helpers 2 173 0
Python pendulum Fluent helpers 170 0
Python pendulum Attributes and Properties 197 0
Python pendulum Localization 210 118
Python pendulum parsing 2 203 23
Python pendulum Parsing 1 210 61
Python pendulum 2 231 57
Python pendulum basics 204 9
python library Pendulum 206 33
python winsound.SND_PURGE and winsound.SND_WAIT 247 5
Python winsound.SND_NOSTOP 256 1
Python winsound.SND_NODEFAULT 219 1
python winsound.SND_ASYNC not excecuting problem 224 2
Python winsound functions 274 3
python winsound.SND_ALIAS 258 1
Python winsound.MessageBeep() 391 1
Python winsound basic introduction 359 1