Making a Alarm Clock in Python
Hey Guys,
Today i will be instructing on how to make an Interesting Project in Python. That is how to make an Alarm Clock.
Nowadays Alarms are very useful as it helps us to wake up and go to Work, School and do various Activities on time. Let us see on how to make this useful thing on one of the famous, easiest Programming Language, the Python.
How to make an Alarm Clock in Python?
Making a Alarm clock in Python is very easy to make and it depends on a few libraries or modules that needs to installed in python. The Following are the Python Modules: Py - Time, Pyttsx3, Pyautogui. First Install these Modules by "pip install pyttsx3". The Time module comes built-in so no need to download. Click to see my Post on what are Modules - Click Here!
The Following are the Code for making a Python Alarm:
def Alarm():
import time, pyautogui, pyttsx3
Time = int(input("Enter a Time in Seconds: "))
print("Your Alarm has been Set...")
print("Starting in...")
pyautogui.countdown(3)
print("Your Timer has been Set.")
if Time > 300:
print("The Seconds Entered is Too High to set. Please Lower it.")
Alarm()
else:
Voice = pyttsx3.init()
Voice.say("Starting...")
Voice.runAndWait()
pyautogui.countdown(Time)
Voice2 = pyttsx3.init()
Voice2.say("Timer Ended! The Timer has Ended. Please Stop it.")
Voice2.runAndWait()
stop = input("Stop: ")
if stop.lower() == "stop":
print("Bye!")
else:
print("Not Valid!")
Alarm()
The Code is first initiated by Downloading the Modules and then it is placed inside a function. The Alarm only asks time in seconds and if it is entered more than 300, will show a error. You can change it to as many seconds as you want, but i Coded it so that 5 minutes would be the highest to reduce the time of the running program.
Then it all takes place inside the if Statements to check if it is exceeding 300.
To get the voice, check out the Following code:
Voice = pyttsx3.init()
Voice.say("Starting...")
Voice.runAndWait()
A sound is started when the Timer ends and Voila, It works!
Hope you Guys, Loved todays Content and by the way Sorry for not posting for 2 weeks due to personal works and Anyway thanks for giving views even in that Siutuation.
Please View, Read, Share, Follow, Subscribe, Comment, Review, Support
Please share this blog with 20 of your Friends and Family
By the Blog Author.
0 Comments