-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarm.py
35 lines (29 loc) · 865 Bytes
/
alarm.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
import pyttsx3
import datetime
import os
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
for voice in voices:
if "zira" in voice.name.lower():
engine.setProperty("voice", voice.id)
break
engine.setProperty("rate", 170)
def speak(audio):
engine.say(audio)
engine.runAndWait()
extractedtime = open("alarmtext.txt", "r")
time = extractedtime.read().strip() # Remove trailing whitespaces
extractedtime.close()
deletetime = open("alarmtext.txt", "r+")
deletetime.truncate(0)
deletetime.close()
def ring(time):
while True:
currenttime = datetime.datetime.now().strftime("%H:%M:%S")
if currenttime == time:
speak("Wake up sir, It's time")
os.startfile("music.mp3")
break # End the loop once alarm time is reached
else:
continue
ring(time)