Python:发出哔哔声 [英] Python: Making a beep noise

查看:22
本文介绍了Python:发出哔哔声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让程序发出哔哔声.我在 Windows 机器上.我看过 http://docs.python.org/library/winsound.html

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?

推荐答案

在Windows上,如果你只想让电脑发出哔哔声:

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)

winsound.Beep() 可用于您希望发出哔声的任何地方.

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

这篇关于Python:发出哔哔声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆