Python: Making a beep noise

Marc Brigham picture Marc Brigham · Jun 30, 2011 · Viewed 199.6k times · Source

I'm trying to get the program to give me a beeping noise. I'm on a windows machine. I've looked at http://docs.python.org/library/winsound.html

But not sure how I can program this with a barcode scanner.

Here is my code for the serial barcode scanner.

ser = serial.Serial()
ser.baudrate = 9600

#for windows
ser.port = 2 #for COM3

ser.open()
ser.write('hello')
ser.close()

UPDATE: Since I'm annoying my co-workers with the beep. Can I get it to come through the audio jack for headphones?

Answer

CyanRook picture CyanRook · Jun 30, 2011

On Windows, if you want to just make the computer make a beep sound:

import winsound
frequency = 2500  # Set Frequency To 2500 Hertz
duration = 1000  # Set Duration To 1000 ms == 1 second
winsound.Beep(frequency, duration)

The winsound.Beep() can be used wherever you want the beep to occur.