File size: 783 Bytes
c640bc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Created By: ishwor subedi
Date: 2023-12-30
"""

import pygame


class AlertService:
    def __init__(self, alert_sound_path):
        self.alert_sound_path = alert_sound_path
        pygame.init()

    def play_alert(self):
        """
        This function help us to play the alert sound
        :return:
        """
        try:
            pygame.mixer.init()
            alert_sound = pygame.mixer.Sound(self.alert_sound_path)
            alert_sound.play()
            pygame.time.wait(int(alert_sound.get_length() * 1000))  # Wait for the sound to finish playing
        except pygame.error as e:
            print(f"Error playing alert sound: {e}")


if __name__ == '__main__':
    alert_service = AlertService("resources/alert/alert.mp3")
    alert_service.play_alert()