Alarm Using PYTHON

Jainkrishna
1 min readJul 21, 2021

Maybe you have just begun coding in Python. Maybe the entire outset seems inconclusive since you have been working with regular IDEs and would like to obtain a bit more out of what your code does on the respective console and maybe a little music or tune might just liven it up.

This article serves the purpose of introducing to you the winsound module, an object or file with a set of attributes or functions, specific to the task of generating or playing sound or a sound file.

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

Since, the winsound module is a builtin, there is no need for you to install it prior to executing it.

import winsound

The basic action would be to and then based upon the kind of output you would like, type out the following functions:

  • winsound.Beep( )

The functionality devoted to this method is 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.

  • winsound.PlaySound( )
    With the PlaySound function, things can get slightly advanced, not to mention interesting. Keep in mind that this function is only compatible with .wav files. Two parameters are passed in the function: ‘filename’ and the flag – winsound.SND_FILENAME, which is required for the Platform API to refer to the output file.

--

--