Python Batch 3 Report
Python Batch 3 Report
On
ALARM CLOCK
Submitted
to
CMR Technical Campus, Hyderabad
BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE & ENGINEERING
by
A.MANISH-227R1A0504
1
MINI PROJECT- Alarm clock
CERTIFICATE
This to certify that, the Presentation entitled “Alarm Clock” is submitted by A.Manish-
227R1A0504 of B.Tech Computer Science and Engineering, In Partial fulfillment for
the requirement of the Presentation and for the award of the Degree of Bachelor of
Technology during the academic year 2023-24.
Subject Faculty
Ms. P Rashmitha
2
MINI PROJECT- Alarm clock
ABSTRACT
The Python script, designed as an alarm clock, employs a multifaceted approach to
time management and user interaction. It begins by soliciting user input for a specific
alarm time, meticulously parsing the input to extract the hour, minute, second, and
AM/PM period. The core of the script resides in an infinite loop, where it
continuously retrieves the current time using the datetime module and compares it
with the user-specified alarm time.
When a match occurs, signaling the designated time for the alarm, the script invokes
the Pygame library to deliver an audio alert. This auditory cue is facilitated through
the loading and playing of an MP3 file, allowing for a customizable and engaging
alarm experience. The script orchestrates a brief pause, currently set at 10 seconds,
to permit the full playback of the alarm sound. Following this interval, Pygame stops
the audio, and the loop concludes, concluding the program.
This project encapsulates the integration of user input processing, real-time clock
synchronization, and audio playback functionalities. While the current
implementation provides a basic and functional alarm clock, further refinement
could involve incorporating features like error handling to enhance robustness,
implementing a more intuitive user interface, and potentially expanding the range of
supported audio formats for a more versatile user experience. The script serves as a
foundation for a customizable and extensible alarm clock application in the Python
programming environment.
3
MINI PROJECT- Alarm clock
Table of Contents:
S.NO CONTENTS PAGE NUMBER
1 Introduction
5
2 Literature survey
6
3 System design
7,8,9
6 Working algorithm
15-16
7 Implementation
14-18
8 Result
19-21
9 Conclusion 22
4
MINI PROJECT- Alarm clock
1.INTRODUCTION
In the realm of practical Python applications, the development of a non-GUI alarm
clock stands as a testament to the language's versatility and simplicity. This project
addresses the fundamental need for time management and user-defined reminders,
offering a command-line-based solution that seamlessly integrates user input
processing, real-time clock monitoring, and audio playback functionalities.
The core objective is to create a reliable and customizable alarm system that allows
users to set specific times for reminders or wake-up calls. Utilizing the Pygame
library for audio handling, the script empowers users to choose their preferred alarm
sounds, enhancing the overall user experience.
This venture serves as an exploration into the synergy of Python's datetime module,
user interaction through the command line, and the integration of external libraries
for multimedia functionalities. As users input their desired alarm time, the script
continuously monitors the system clock, ensuring precision in triggering the selected
audio alert when the specified time arrives.
While the current implementation provides a functional alarm clock, there exists
ample opportunity for expansion and refinement. Future iterations could include
error handling mechanisms, a more intuitive user interface, or even the incorporation
of additional features to elevate the alarm clock's utility.
Embark on this journey to create a robust and straightforward Python alarm clock,
showcasing the language's prowess in addressing everyday needs through elegant
yet pragmatic solutions. This project not only provides a practical tool but also serves
as an educational endeavor, offering insights into datetime handling, user input
validation, and the integration of external libraries within the Python ecosystem.
5
MINI PROJECT- Alarm clock
2. LITERATURE SURVEY
The literature survey for the alarm clock project using Python without a graphical
user interface (GUI) encompasses several key areas. Firstly, investigations into time
management systems provide foundational knowledge regarding the design and
implementation of alarm functionalities. Researchers have explored algorithms for
precise time tracking and synchronization with system clocks, offering insights into
strategies for triggering alarms accurately. Understanding the broader context of
time management systems aids in contextualizing the specific choices made in the
project to achieve reliable alarm functionality.
Furthermore, the literature survey explores best practices in user input handling and
scripting within the Python environment. Console-based applications, such as the
alarm clock project, demand effective strategies for user interaction and error
handling. Research in this area encompasses topics like input validation, creating
user-friendly interfaces in command-line applications, and scripting practices for
automation. Insights from these studies inform the design choices made in the
project to ensure a robust and user-friendly alarm clock application without a GUI.
6
MINI PROJECT- Alarm clock
3.SYSTEM DESIGN
The
User Input:
The user provides the desired alarm time in the format (HH:MM:SS AM/PM).
The input alarm time is parsed to extract the hour, minute, seconds, and period
(AM/PM).
Initialization:
The script initializes a continuous loop to check the current time against the set alarm
time.
Time Comparison:
Inside the loop, the current time is continuously compared with the set alarm time.
Alarm Trigger:
If the current time matches the set alarm time, the alarm is triggered.
Audio Alert:
Volume Control:
Sound Playback:
The Pygame mixer loads the specified audio file and plays it.
7
MINI PROJECT- Alarm clock
Duration:
The sound plays for a fixed duration (10 seconds in this case) to alert the user.
Alarm Stop:
After the sound has played for the specified duration, it stops, and the loop exits.
Components:
Datetime Module:
Pygame Library:
User Input:
Error Handling:
Implement error handling to validate user input for a correct time format.
Configurability:
Make the alarm sound file path configurable rather than hardcoded.
Cross-Platform Compatibility:
Background Execution:
Consider making the script run in the background so that the user doesn't need to
keep the terminal open.
Notification:
Logging:
This design outlines the key components and flow of the alarm system. You can
further enhance and customize it based on your specific requirements.
9
MINI PROJECT- Alarm clock
Python Version:
External Libraries:
pygame: This library is used for playing the alarm sound. You can install it using
the following command:
Copy code
Operating System:
The script should be compatible with different operating systems (Windows, Linux,
macOS). Ensure that the required libraries, especially pygame, are supported on the
chosen operating system.
Hardware Requirements:
The script itself is not resource-intensive, and it should run on standard desktop or
laptop hardware.
Ensure the machine has a functioning speaker or audio output device for the alarm
sound to be heard.
Storage:
10
MINI PROJECT- Alarm clock
The script does not require significant storage space. It only loads a small audio file
for the alarm sound.
Miscellaneous:
Ensure the machine has an active internet connection if you need to install the
pygame library from the Python Package Index (PyPI).
Audio File:
File Path:
User Input:
The script relies on user input for setting the alarm time. Ensure that the user
provides input in the specified format (HH:MM:SS AM/PM).
Execution Environment:
Ensure the system has the necessary permissions to execute the script and access the
required resources (e.g., file access permissions).
Dependencies:
Confirm that the required Python dependencies are installed. You can use a virtual
environment to isolate dependencies if needed.
Consider documenting these requirements in your report, and mention any additional
considerations specific to your use case or environment.
11
MINI PROJECT- Alarm clock
5.FUNCTIONAL REQUIREMENTS
Functional requirements describe the features and functionalities that a software
system or project should provide. Based on your alarm project, here are some
functional requirements you can consider:
The system should validate the user input for the alarm time to ensure it follows
the correct format (HH:MM:SS AM/PM).
Users should be able to configure the alarm sound by providing the path to the
desired audio file.
The system should support various audio formats and handle errors gracefully if
the file is not found or not supported.
Snooze Functionality:
Include a snooze button or functionality that allows users to snooze the alarm for
a specified duration.
After snoozing, the alarm should ring again after the snooze duration.
Consider developing a simple graphical user interface (GUI) for the alarm clock to
enhance the user experience.
The UI could include fields for setting the alarm time, configuring the alarm sound,
and snooze options.
12
MINI PROJECT- Alarm clock
Implement volume control functionality to allow users to set the volume of the
alarm sound.
Multiple Alarms:
Each alarm should be independent of others and trigger the configured sound at
the specified time.
Error Handling:
Cross-Platform Compatibility:
Ensure that the alarm system is compatible with different operating systems
(Windows, Linux, macOS).
User Notifications:
Consider adding visual notifications or messages to alert the user when an alarm is
set, snoozed, or stopped.
Allow users to choose between 12-hour and 24-hour time formats for setting
alarms.
Logging:
13
MINI PROJECT- Alarm clock
Provide an option to pause the alarm temporarily, allowing users to resume it later
without resetting the entire alarm.
Accessibility Features:
Remember, these are general suggestions, and you can customize them based on
the specific needs and scope of your project.
14
MINI PROJECT- Alarm clock
6.WORKING ALGORITHM
This code sets up a simple alarm clock in Python using the datetime, pygame, and
time modules. Here's a breakdown of the code:
User Input:
The program prompts the user to input the desired alarm time in the format
"HH:MM:SS AM/PM".
The inputted time is processed to extract the hour, minute, seconds, and period
(AM/PM).
Setting up Alarm:
The program enters a loop to continuously check the current time against the set
alarm time.
Inside the loop, the current time components (hour, minute, seconds, and period) are
obtained using the datetime.now() function.
If the current time matches the set alarm time (hour, minute, seconds, and period),
the program prints "Wake Up!".
It initializes the pygame mixer, loads an alarm sound file, sets the volume to
maximum, and plays the sound.
15
MINI PROJECT- Alarm clock
The program then sleeps for 10 seconds (adjustable) to allow the sound to play.
After playing the sound, the pygame mixer is stopped, and the loop is exited using
break.
Note: Ensure to replace the placeholder path with the correct location of your alarm
sound file. The code uses datetime for time handling, pygame for sound, and time
for introducing
16
MINI PROJECT- Alarm clock
7.IMPLEMENTATION
from datetime import datetime
import pygame
import time
alarm_components = alarm_time[:-6].split(":")
alarm_hour = int(alarm_components[0])
alarm_minute = int(alarm_components[1])
alarm_seconds_period = alarm_time[-6:]
alarm_seconds = int(alarm_seconds_period.split(':')[1][:2]) if ':' in
alarm_seconds_period else 0
alarm_period = alarm_seconds_period[-2:].upper()
print("Setting up alarm..")
while True:
now = datetime.now()
current_hour = int(now.strftime("%I"))
current_minute = int(now.strftime("%M"))
17
MINI PROJECT- Alarm clock
current_seconds = int(now.strftime("%S"))
current_period = now.strftime("%p")
print("Wake Up!")
pygame.mixer.init()
pygame.mixer.music.load("C:\\Users\\DELL\\OneDrive\\Desktop\\python
projects\\extreme_alarm_clock.mp3") # Replace with the correct path
pygame.mixer.music.play()
pygame.mixer.music.stop()
break
18
MINI PROJECT- Alarm clock
RESULT
19
MINI PROJECT- Alarm clock
RESULT: The provided code is an alarm clock program in Python. The result of
running this code is that the program prompts the user to input a time for the alarm
in the format "HH:MM:SS AM/PM." The program then sets up an alarm and
continuously checks the current time. If the current time matches the specified alarm
time, it prints "Wake Up!" and plays an alarm sound (assuming the correct path to
the sound file is provided). The alarm sound plays for 10 seconds, and then the
program stops, ending the execution.
User Input:
The program prompts the user to input a time for the alarm in the format
"HH:MM:SS AM/PM."
Parsing Input:
The inputted time is parsed to extract the hour, minute, seconds, and period
(AM/PM).
Setting Up Alarm:
The program enters a loop where it continuously checks the current time using the
datetime module.
Comparison:
The current time is compared with the user-specified alarm time. If they match
(including hour, minute, seconds, and AM/PM), the alarm is triggered.
Wake-Up Message:
If the alarm is triggered, the program prints "Wake Up!" to the console.
20
MINI PROJECT- Alarm clock
Sound Duration:
The program then sleeps for 10 seconds (time.sleep(10)) to allow the alarm sound
to play. You can adjust this duration as needed.
Keep in mind that for this code to work, you need to have the pygame library
installed (pip install pygame), and you should replace the placeholder path with the
correct path to your alarm sound file.
21
MINI PROJECT- Alarm clock
9. CONCLUSION
In conclusion, the provided Python code serves as a basic alarm clock application,
allowing users to set an alarm time and be awakened by a specified sound. The
program utilizes the `datetime`, `pygame`, and `time` modules to manage time-
related operations and audio playback.
The alarm time is inputted by the user in the "HH:MM:SS AM/PM" format and is
subsequently parsed to extract the hour, minute, seconds, and period components.
The program then enters a continuous loop, repeatedly checking the current time
against the set alarm time.
Upon reaching the designated alarm time, the application triggers the alarm,
notifying the user with a "Wake Up!" message and playing an alarm sound loaded
from a specified file path. The volume is set to maximum during playback, and the
sound persists for a duration of 10 seconds, as indicated by the `time.sleep(10)`
statement.
22