forked from Shubham2582/driving_management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert_system.py
40 lines (37 loc) · 1.76 KB
/
alert_system.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import simpleaudio as sa
import os
# Function to determine the severity of drowsiness
def determine_drowsiness_severity(ear_value):
if ear_value < 0.2:
return 'high'
elif ear_value < 0.3:
return 'medium'
else:
return 'low'
# Function to play alert sounds based on drowsiness severity
def play_alert_sound(severity):
script_dir = "D:/codes/Aiml" # Use the directory path of the current script
sound_dir = os.path.join(script_dir, 'sounds') # Create a directory path for the sounds folder
if severity == 'low':
# Play a mild alert sound
sound_file = os.path.join(sound_dir, 'low_alert_sound.wav') # Replace with the appropriate path to the low alert sound file
wave_obj = sa.WaveObject.from_wave_file(sound_file)
play_obj = wave_obj.play()
play_obj.wait_done()
elif severity == 'medium':
# Play a moderate alert sound
sound_file = os.path.join(sound_dir, 'medium_alert_sound.wav') # Replace with the appropriate path to the medium alert sound file
wave_obj = sa.WaveObject.from_wave_file(sound_file)
play_obj = wave_obj.play()
play_obj.wait_done()
elif severity == 'high':
# Play a high alert sound
sound_file = os.path.join(sound_dir, 'high_alert_sound.wav') # Replace with the appropriate path to the high alert sound file
wave_obj = sa.WaveObject.from_wave_file(sound_file)
play_obj = wave_obj.play()
play_obj.wait_done()
# Example usage of the alert system based on drowsiness severity
if __name__ == "__main__":
ear_value = 0.25 # Example EAR value obtained from drowsiness detection
severity = determine_drowsiness_severity(ear_value)
play_alert_sound(severity)