我正试图从 python 脚本中吱吱作响。我将立即进行预订 - 哔声系统实用程序发出完美的吱吱声 - 即 说话者还活着,系统知道他。我在busybox包中的beep.c源代码的图像和相似性中执行此操作,但已经在python中:
#!/usr/bin/python
import os
import fcntl
import time
KIOCSOUND = 0x4B2F
CLOCK_TICK_RATE = 1193180
def beep(hz, len):
fd = os.open("/dev/console", os.O_WRONLY)
try:
fcntl.ioctl(fd, KIOCSOUND, int(CLOCK_TICK_RATE / hz))
try:
time.sleep(len)
finally:
fcntl.ioctl(fd, KIOCSOUND, 0)
finally:
os.close(fd)
if __name__ == '__main__':
beep(440, 0.5)
我得到一个错误:
fcntl.ioctl(fd, KIOCSOUND, int(CLOCK_TICK_RATE/hz))
OSError: [Errno 25] Not a tty
结果 - 启动哔声过程。但不知何故,它并不漂亮。我在 python 中做错了什么?