'Need to set off an sound after 10 seconds in a python project
I am currently trying the driver drowsiness detection project using python and until now it can detect the drowsiness, I want to play a sound after 10 seconds if it continuously shows drowsy. How can I program it?
Solution 1:[1]
At the first time the condition becomes true, start a performance timer. Once the condition is false, set start to False. If the performance timer reaches 10 seconds, play the sound. Might look something like this:
import time
start = False
while True:
if condition and not start:
start = time.perf_counter()
if not condition:
start = False
if start > 10:
start = False
playsound("my_sound.mp3", block=False)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
