在python中使用什么在5秒后启动警报

问题描述

ve writed a code in python to detect when the driver have the eyes closed and whe he is not looking on the road.I want to start an alarm after 5 sec. when the eyes are closed or he is looking on the left or right.I尝试使用 winsound 或 playsound,但警报滞后并且听起来像回声。我将在代码的下面部分留下我如何定义函数 playsound、实际代码如何以及在哪里我想放置它。谢谢!

功能

def play_sound():
winsound.PlaySound("Alarma2.wav",winsound.SND_ASYNC)

我放置它的第一个地方

        if EAR < 0.26:
         timer = threading.Timer(5,play_sound)
         timer.start()

        cv2.putText(frame,"Alarma",(20,100),cv2.FONT_HERShey_SIMPLEX,3,(0,255),4)
        print("X")
    print(EAR)
    if EAR > 0.26:
        winsound.PlaySound(None,winsound.SND_PURGE)

第二个

        if gaze_ratio <= 1:
        timer = threading.Timer(5,play_sound)
        timer.start()

        cv2.putText(frame,"RIGHT",(50,font,2,3)
        new_frame[:] = (0,255)

    elif 1 < gaze_ratio < 1.7:
        winsound.PlaySound(None,winsound.SND_PURGE)
        cv2.putText(frame,"CENTER",3)

    else:
        new_frame[:] = (255,0)
        cv2.putText(frame,"LEFT",3)
        timer = threading.Timer(5,play_sound)
        timer.start()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)