Tuesday 11 June 2019

audio - Python: Making a beep noise



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



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.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...