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 69 0
Python Pendulum Limitations in DJANGO 95 0
Python Pendulum Limitations in MYSQLCLIENT 79 0
Python Pendulum Limitations in SQLITE3 80 0
Python Pendulum Testing 2 83 0
Python Pendulum Testing 100 0
Python Pendulum Range 97 0
Python Pendulum Period 3 95 0
Python Pendulum Period 2 92 0
Python Pendulum Period 88 0
Python Pendulum Properties and Duration Methods 2 88 0
Python Pendulum Properties and Duration Methods 93 0
Python Pendulum Instantiation 93 0
Python Pendulum Duration 90 0
Python Pendulum TImezone usage 2 81 0
Python Pendulum Timezone usage 80 0
Python Pendulum Switching Timezones 86 0
Python Pendulum Shifting Time to Transition 97 0
Python Pendulum Normalization 96 0
Python Pendulum Modifiers 2 98 0
Python Pendulum Modifiers 95 0
Python Pendulum Difference for Humans 2 130 0
Python Pendulum Difference for Humans 100 0
Python Pendulum Difference 106 0
Python pendulum Substraction 114 0
Pyhton pendulum Addition 110 0
Python pendulum Comapaison part 2 103 0
Python Pendulum Comparison 107 0
Python Pendulum Localized Formats and Escaping characteristics 101 0
Python pendulum Tokens 110 0
Python pendulum Formatter 103 0
Python pendulum Common Formats 108 0
Python pendulum String Formatting 112 0
Python pendulum Fluent helpers 2 105 0
Python pendulum Fluent helpers 95 0
Python pendulum Attributes and Properties 99 0
Python pendulum Localization 122 118
Python pendulum parsing 2 118 23
Python pendulum Parsing 1 127 61
Python pendulum 2 129 57
Python pendulum basics 122 9
python library Pendulum 123 33
python winsound.SND_PURGE and winsound.SND_WAIT 138 5
Python winsound.SND_NOSTOP 157 1
Python winsound.SND_NODEFAULT 147 1
python winsound.SND_ASYNC not excecuting problem 150 2
Python winsound functions 169 3
python winsound.SND_ALIAS 178 1
Python winsound.MessageBeep() 185 1
Python winsound basic introduction 224 1