6

I need a python way to beep the system/motherboard speaker independent of the speakers attached to my computer. I don't always have the speakers turned on, so i need to beep the motherboard speaker.

All the libraries i've seen (winsound especially), just play a sound through the speakers attached to my computer. I'd like to beep the system/motherboard speaker.

Is there a way to beep the system speaker? I'm okay with Windows dependent libraries.

user208145
  • 369
  • 4
  • 13

2 Answers2

2

just print '\a' to stdout

print '\a'   # for python3, print('\a')

if you don't want a newline be printed

print '\a\b', # for python3. print('\a\b', end='')
sys.stdout.flush()
d2207197
  • 1,284
  • 1
  • 9
  • 10
  • What's the difference between using your way and the one recommended by aIKid? – confused00 Sep 30 '16 at 11:44
  • 3
    The result is the same. '\a' is '\x07'. But in order to print a '\a' character, you don't have to call `echo` as a subprocess, just print it. `echo` is a simple command for printting. Why not just print it in python code? – d2207197 Oct 01 '16 at 03:56
1

Use a call to the command line:

>>> from subprocess import call
>>> call(["echo", u'\x07'])

As $ echo ^G - ^G is the character for motherboard beep - will produce that sound, to do it with python you only have to execute the comand.

aIKid
  • 26,968
  • 4
  • 39
  • 65