Play simple beep with python without external library Play simple beep with python without external library python python

Play simple beep with python without external library


If you're on a Unix terminal, you can print "\a" to get a terminal bell:

>>> def beep():...     print "\a">>> beep()

Of course, that will print a newline too… So sys.stdout.write("\a") might be better. But you get the idea.


On windows:

import winsound         # for sound  import time             # for sleepwinsound.Beep(440, 250) # frequency, durationtime.sleep(0.25)        # in seconds (0.25 is 250ms)winsound.Beep(600, 250)time.sleep(0.25)

34.4. winsound — Sound-playing interface for Windows:

http://docs.python.org/2.6/search.html?q=sound&check_keywords=yes&area=default

See also:Clear screen and beep for various platforms. (Python recipe) http://code.activestate.com/recipes/577588-clear-screen-and-beep-for-various-platforms/


On Android with QPython this is how it goes:

import androidhelperdroid=androidhelper.Android()droid.generateDtmTones('0',100)