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.Thewinsound
module is defined only for execution on a Windows Platform, hence the name WINsoundInstallation
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 byimport winsoundFunctions
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.
#code
import winsound
#outputsystem will produce a ‘Beep’ sound with the given frequencyfor the given duration of time.
winsound.
PlaySound()
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_FILENAME The sound parameter is the name of a WAV file. SND_LOOP Play the sound repeatedly SND_MEMORY The sound parameter to PlaySound() is a memory image of a WAV file, as a bytes-like object. SND_ASYNC Return immediately, allowing sounds to play asynchronously. SND_NODEFAULT If the specified sound cannot be found, do not play the system default sound. SND_NOSTOP Do not interrupt sounds currently playing.
#code
import winsound print("Playing the file 'Police siren.wav'") # winsound.PlaySound('filename', flag) winsound.PlaySound('mixkit-police-siren-us-1643.wav', winsound.SND_FILENAME)
#output
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
Comments