Python Batch 3 Report

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

MINI PROJECT- Alarm clock

A Presentation Report for OOPS Through PYTHON LAB (22CS307PC)

On
ALARM CLOCK
Submitted
to
CMR Technical Campus, Hyderabad

In Partial fulfillment for the requirement of the Award of the Degree of

BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE & ENGINEERING

by
A.MANISH-227R1A0504

Under the esteemed guidance of


MS. P RASHMITHA
Assistant Professor

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


CMR TECHNICAL CAMPUS
An UGC Autonomous Institute
Accredited by NBA & NAAC with A Grade
(Approved by AICTE, Affiliated to JNTU, Hyderabad)
Kandlakoya (V), Medchal (M), Hyderabad-501 401
(2023-2024)

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

4 System and hardware


10,11
requirements
5 Functional requirements
12,13,14

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.

In parallel, a focus on audio processing and playback in Python is crucial for


comprehending the project's use of the Pygame library. Literature in this domain
delves into the intricacies of playing sound files in command-line applications,
covering aspects such as file format compatibility, optimization techniques, and
considerations for a seamless user experience. This segment of the literature survey
contributes to discerning the rationale behind leveraging Pygame for audio playback
and potential alternatives in the Python ecosystem.

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).

Alarm Time Parsing:

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:

The system uses the Pygame library to play an audio file


("extreme_alarm_clock.mp3") when the alarm is triggered.The audio file path is
hardcoded in the script and should be replaced with the correct path.

Volume Control:

The volume of the audio is set to the maximum.

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:

Used to get the current system time.

Pygame Library:

Utilized for playing the alarm sound.

User Input:

The user provides the alarm time.

Considerations and Improvements:

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.

User Interface (UI):

Develop a graphical or command-line interface for a better user experience.

Cross-Platform Compatibility:

Ensure the script is compatible with different operating systems.


8
MINI PROJECT- Alarm clock

Background Execution:

Consider making the script run in the background so that the user doesn't need to
keep the terminal open.

Notification:

Integrate a notification system to provide visual or additional alerts.

Logging:

Implement logging for tracking alarm triggers and errors.

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

4.SYSTEM AND HARDWARE REQUIREMENTS


The provided Python script is a simple alarm clock program that uses the pygame
library to play an alarm sound when the specified alarm time is reached. For
reporting the system and hardware requirements, you need to consider both the
Python script's requirements and the dependencies it relies on. Here's a breakdown:

Python Version:

Python 3.x (where x is the latest version at the time of use).

External Libraries:

pygame: This library is used for playing the alarm sound. You can install it using
the following command:

Copy code

pip install pygame

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:

The script expects an audio file ("extreme_alarm_clock.mp3") to be present at the


specified path. Ensure the file exists and is in the correct format (MP3).

File Path:

Make sure to replace the placeholder path


("C:\Users\DELL\OneDrive\Desktop\python projects\extreme_alarm_clock.mp3")
with the actual path to the alarm sound file on your system.

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:

User Input Validation:

The system should validate the user input for the alarm time to ensure it follows
the correct format (HH:MM:SS AM/PM).

Provide appropriate error messages if the input is incorrect.

Configurable Alarm Sound:

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.

User Interface (UI):

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.

Alarm Volume Control:

12
MINI PROJECT- Alarm clock

Implement volume control functionality to allow users to set the volume of the
alarm sound.

Multiple Alarms:

Extend the system to support setting multiple alarms at different times.

Each alarm should be independent of others and trigger the configured sound at
the specified time.

Error Handling:

Implement robust error handling throughout the code to handle unexpected


scenarios gracefully.

Provide meaningful error messages to help users troubleshoot issues.

Cross-Platform Compatibility:

Ensure that the alarm system is compatible with different operating systems
(Windows, Linux, macOS).

Address any platform-specific issues that may arise.

User Notifications:

Consider adding visual notifications or messages to alert the user when an alarm is
set, snoozed, or stopped.

Customizable Alarm Period:

Allow users to choose between 12-hour and 24-hour time formats for setting
alarms.

Logging:

Implement logging functionality to keep a record of alarm activities, such as when


alarms are set, triggered, snoozed, or stopped.

Pause and Resume Alarm:

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:

Consider adding accessibility features such as text-to-speech for alarm notifications


or visual indicators for users with hearing impairments.

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".

Parsing User Input:

The inputted time is processed to extract the hour, minute, seconds, and period
(AM/PM).

The components are converted to integer values for comparison.

Setting up Alarm:

The program enters a loop to continuously check the current time against the set
alarm time.

Checking Alarm Time:

Inside the loop, the current time components (hour, minute, seconds, and period) are
obtained using the datetime.now() function.

Alarm Trigger Condition:

If the current time matches the set alarm time (hour, minute, seconds, and period),
the program prints "Wake Up!".

Playing Alarm Sound:

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.

Ending the Program:

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_time = input("Enter the time of alarm to be set (HH:MM:SS AM/PM): ")

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")

if alarm_period == current_period and alarm_hour == current_hour and


alarm_minute == current_minute and alarm_seconds == current_seconds:

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.set_volume(1.0) # Set volume to maximum

pygame.mixer.music.play()

time.sleep(10) # Allow the sound to play for 10 seconds (adjust as needed)

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.

Playing Alarm Sound:


The pygame module is initialized, and an alarm sound file is loaded (replace the
placeholder path with the correct path to your sound file).

20
MINI PROJECT- Alarm clock

The volume is set to maximum, and the sound is played using


pygame.mixer.music.play().

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.

Stopping the Sound:


After the specified duration, the alarm sound is stopped using
pygame.mixer.music.stop().

Ending the Program:


The break statement is used to exit the loop, ending the program.

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.

Overall, this straightforward alarm clock script provides a basic demonstration of


time-based functionalities in Python, offering users a simple way to set and receive
alarms. Further enhancements, such as incorporating additional features or
improving user interaction, could be implemented to make the application more
robust and user-frie

22

You might also like