What is winsound.Beep() in Python 3?

Overview

The winsound module in Python 3 provides an interface to interact with the sound playing machinery in Windows. The Beep function plays a beep of the specified frequency for the specified duration. If the system is not able to produce the beep sound on the speaker, a RuntimeError is raised. The syntax of the Beep function is as follows:

winsound.Beep(frequency, duration)

Parameters

  • frequency is a value between 37 to 32767 Hertz that specifies the frequency of the beep.
  • duration is the number of milliseconds for which the beep must be played.

Return value

  • Beep returns None.

Example

The following code provides an example of how to use the Beep function:

import winsound
winsound.Beep(1500, 2000)

In the example above, the system will play a beep sound with a frequency of 1500 Hertz for 2 seconds.

Copyright ©2024 Educative, Inc. All rights reserved