Documentation CS Proj 12th Final
Documentation CS Proj 12th Final
Buddy -
Your Perfect Virtual Assistant
Done By,
HARIRAM S
SHALIN S K
SIDTHARTH K
R
The Hindu Colony
Chellammal Vidyalaya
Senior Secondary School
NANGANALLUR, CHENNAI-61
XII-Std
Name…………………… Class……………………
Register No…………… Year……………….
Internal Examiner
Internal
Assessment External Examiner
Art Integrated Project
Buddy - Your Perfect Virtual Assistant
AIL Serial Number – 4.1.1.1.11
Content
S.No. Topic
1 Introduction
2 Hardware & Software used
3 Data dictionary
4 Process logic
5 Menu description
6 Source code
7 Input, Output screenshots
8 Pairing State
9 Future scope of the Project
10 Bibliography
Introduction
Buddy is your perfect virtual assistant. It is highly
useful in doing daily tasks
without much effort.
It provides a hassle free
experience for the user and
does complex tasks at
ease.
It contains all the enough
options to cater to the day-
to-day of the users.
It takes voice
inputs and gives
output in various
forms.
It accesses almost
all the daily apps
we use and makes
them easy to use.
Hardware & Software used
Hardware:
Processor: intel core i7
Printer: HP 104A Original
Black Laser.
Keyboard: HP 4SC12PA
Memory: RAM 8 GB
Software:
Operating System: Windows
10
Python IDLE (3.8.3 64 bit)
MS Word 2016
Snipping tool
HTML
Data dictionary
String-
L-To store the audio input given
by the user
Files-
image2- prints the logo when called.
data- contains the contents of the
SQL table.
Functions-
o mainmenu()-The entire program is
written as a function for its ease of
usage.
o submit()- Used for getting login &
password details.
o greetMe()- Used to greet the user
based on the time of usage.
o quote()- Used to give a random quote
when the user asks for it.
o song()- Used to play a random song
when the user asks for it.
o joke()- Used to display a random joke
when the user asks for it.
o sos()- Used to display the emergency
numbers.
o assistant_speaks()- Used to give the
voice output for the given text.
o get_audio()- Used to get audio input
from the user.
Process Logic
The main goal of buddy is to fulfill the
needs of the users in an easy way. In
buddy the entire code is voice assisted
i.e. it is fully operated by voice,
nowhere text input is needed to
operate the virtual assistant. The
menus are continuously driven until the
user wants to stop the code from
executing. The exit menu is given at
different levels both to terminate the
inner menus and also the entire code.
In total, there are five menus which
provide various levels of accessing of
the virtual assistant.
Menu Description
Menu 1: ‘Voice Commands’
This menu is used to give voice inputs
to the virtual assistant to satisfy the
user’s need(s). It opens various
websites/utilities based on the user’s
input.
Menu 2: ‘Converting Voice to Text’
In this menu, the voice input given by
the user is converted into text by our
virtual assistant and is stored in a text
file.
Menu 3: ‘About’
This menu is used to display the logo of
Buddy and its creators. It is a picture
which gives an insight into the project.
Menu 4: ‘Help’
In this menu, the various menus and
sub menus of the program are
displayed, so that the user can easily
know about the project and can use it
with ease.
Menu 5: ‘Exit’
It is used to terminate the execution of
the code. The exit option is given at
various levels for proper termination of
the program.
Source code
import sys
import tkinter as tk
from tkinter import *
from PIL import Image,ImageTk
import speech_recognition as sr
import playsound # to play saved mp3 file
from gtts import gTTS # google text to speech
import os # to save/open files
import wolframalpha # to calculate strings into formula
from selenium import webdriver # to control browser
operations
import datetime
import mysql.connector as msc
import random
import webbrowser
conn = msc.connect(host='localhost', user='root',
password='root', database='mydb')
if conn.is_connected ( ):
print("Successfully connected to Database ... ")
else:
print("Error connecting to MySQL Database !!!")
########image display++++++++
+====================================
==========
#from tkinter import *
#from PIL import Image,ImageTk
#####################################
####################################
#fns of first menu
a="Two aerials get married. The ceremony was rubbish – but
the reception was brilliant."
b="Patient: Doctor, I have a pain in my eye whenever I drink
tea.'\n'Doctor: Take the spoon out of the mug before you
drink."
c="Why did the chicken commit suicide? To get to the other
side."
d="What’s the difference between England and a tea bag? '\n'
The tea bag stays in the cup longer."
e="The doctor to the patient: 'You are very sick'The patient to
the doctor: 'Can I get a second opinion?'The doctor again: 'Yes,
you are very ugly too...'"
L=[a,b,c,d,e]
def joke():
assistant_speaks(random.choice(L))
x="Change alone is permanent'♾️'"
y="Neglect people who neglect you. It'll help you in life"
z="A winner is a loser who has tried once more"
L1=[x,y,z]
L2=['Song.mpeg','Song1.mpeg','Song2.mpeg','Song3.mpeg','S
ong4.mpeg']
def song():
os.system(random.choice(L2))
def quote():
assistant_speaks(random.choice(L1))
def greetMe():
currentH = int(datetime.datetime.now().hour)
if currentH >= 10 and currentH < 5:
assistant_speaks('Hi there,Good Morning! The time
is',currentH)
if currentH >= 5 and currentH < 16:
assistant_speaks('Hi there,Good Afternoon!')
if currentH >= 16 and currentH !=19:
assistant_speaks('Hi there,Good Evening!')
if currentH >= 19 and currentH !=00:
assistant_speaks('Good Night ! It is night')
def SOS():
print("Fire:101")
print("Police:100")
print("Ambulance:108")
print("Child Helpline:1098")
print("Railway Enquiry:139")
print("Senior Citizen Helpline:1091,1291")
#####################################
#####################################
##
num = 1
def assistant_speaks(output):
global num
# num to rename every audio file
# with different name to remove ambiguity
num += 1
print("BUDDY : ", output)
toSpeak = gTTS(text = output, lang ='en', slow = False)
# saving the audio file given by google text to speech
file = str(num)+".mp3 "
toSpeak.save(file)
# playsound package is used to play the same file.
playsound.playsound(file, True)
os.remove(file)
def get_audio():
rObject = sr.Recognizer()
audio = ''
with sr.Microphone() as source:
# recording the audio using speech recognition
audio = rObject.listen(source, phrase_time_limit = 5)
print("Thank you.") # limit 5 secs
try:
text = rObject.recognize_google(audio, language ='en-
US')
print("USER : ", text)
return text
except:
assistant_speaks("Could not understand your audio,
Please try again !")
return 0
#####################################
#####################################
######
def get_audio1():
rObject = sr.Recognizer()
audio = ''
with sr.Microphone() as source:
# recording the audio using speech recognition
audio = rObject.listen(source, phrase_time_limit = 15)
print("Thank you.") # limit 15 secs
try:
text = rObject.recognize_google(audio, language ='en-
UK')
print("USER : ", text)
return text
except:
assistant_speaks("Could not understand your audio,
Please try again !")
return 0
#####################################
#####################################
#######
# declaring string variable
# for storing name and password
root=tk.Tk()
root.title('Buddy - Everything is in finger tip')
root.resizable(0,0)
# setting the windows size
root.geometry("1000x450")
name_var=tk.StringVar()
passw_var=tk.StringVar()
output_var=tk.StringVar()
# creating a label for
# name using widget Label
name_label = tk.Label(root, text = 'Username',
font=('calibre', 15, 'bold'))
# creating a entry for input
# name using widget Entry
name_entry = tk.Entry(root, textvariable =
name_var,font=('calibre',15,'bold'))
# creating a label for password
passw_label = tk.Label(root, text = 'Password', font =
('calibre',15,'bold'))
# creating a entry for password
passw_entry=tk.Entry(root, textvariable = passw_var, font
= ('calibre',15,'bold'), show = '*')
def login ( ):
# creating a button using the widget
# Button that will call the submit function
sub_btn=tk.Button(root,text = 'Submit', font =
('calibre',20,'bold'), command = submit)
output_text = tk.Entry(root, textvariable = output_var,
font = ('calibre',15,'bold'), bg='yellow', width=40)
# placing the label and entry in
# the required position using grid
# method
name_label.grid(row=0,column=0)
name_entry.grid(row=0,column=1)
passw_label.grid(row=1,column=0)
passw_entry.grid(row=1,column=1)
output_text.grid(row=2, column=1,padx = 10, pady = 5 )
sub_btn.grid(row=2,column=0, padx = 10, pady = 5)
# adding image (remember image should be PNG and not JPG)
img = PhotoImage(file = r"dp.gif")
img1 = img.subsample(2, 2)
# setting image with the help of label
Label(root, image = img1).grid(row = 0, column = 2,
columnspan = 2, rowspan = 2, padx = 5, pady = 5)
root.mainloop()
def exit_program():
print("Exiting pgm")
root.destroy ( )
#============ Starting of About ( ) - 3 option
def About ( ):
try :
image2=Image.open("DPforproj.jpeg")
except IOError:
pass
image2.show( )
#===== end of About ( )
#=========== Starting of Help ( ) - 4 option
def Help ( ) :
c=conn.cursor( )
try:
c.execute("create table help (SNo int, MenuName
char(40), Uses varchar(1000)) ")
#print("\n Table is created successfully ... ")
qry = "insert into help values (%s, %s, %s )"
val=(1, 'Voice Commands ' , "This menu is used to give
voice input and it opens various applications from it. These are
Pandemic details, Stopwatch, Joke, Google sheets, Bitcoin
details, Currency converter, Trending Topics, Public Holiday
Information, Wifi Details, Calendar, Movies, Alarm, Calculator,
Play store, Gmail, Novels, Books, Maps, Google, Online games,
YouTube, Meet, News, Wikipedia, Emergency numbers,
Instagram, Twitter, Netflix, GPay, Amazon, Flipkart, Duo,
English Dictionary, Pinterest, Amazon Prime, Hotstar, Tneb ,
School website, Paytm, Translator, swiggy, Uber eats,
Facebook, Ola, Uber, Creators, Quotes, Songs and exit ")
c.execute(qry,val)
qry = "insert into help values (%s, %s, %s )"
val=(2, 'Voice to text' , "This menu is used to convert the
speech you say into tezt. It will be useful when you are the
only person working and ideas flash in your mind and you
want to quickly note them down by saying.")
c.execute(qry,val)
val=(3, 'About' , "This menu gives details about the
project and its creators")
c.execute(qry,val)
val=(4, 'Help' , "This is the current menu. It gives insight
into the project and the various options available in the
project.")
c.execute(qry,val)
val=(5, 'Exit' , "It is used to close the project")
c.execute(qry,val)
conn.commit( )
except msc.Error as err:
print("Help Table is opened for processing !!! ")
c.execute("select * from help")
data = c.fetchall()
if data :
for row in data:
print (row)
else:
print ("help Table is empty")
conn.close( )
c.close( )
greetMe()
# ========== end of Help ( )
#====================================
===================
# starting of Main menu - Buddy 2.0
def MainMenu ( ):
if __name__ == "__main__":
assistant_speaks("Hello, I'm BUDDY. What's your
Name?")
name ='Human'
name = get_audio()
assistant_speaks("Hello, " + str(name)+ '.')
while True:
print("Personal Assistant - Buddy 2.0 .... ")
print("\n 1. Voice Commands \n 2. Converting Voice to
Text \n 3. About \n 4. Help \n 5. Exit ")
assistant_speaks("Speak Your Option")
s=get_audio()
if s == 'voice commands':
while True: #sidhu s code
assistant_speaks("How can I help you
")
assistant_speaks("Speak your command ")
a=get_audio()
assistant_speaks("You asked for "+str(a))
if a=='show pandemic details':
webbrowser.open('https://www.worldometers.info/')
elif a=='open Stopwatch':
webbrowser.open('https://www.online-
stopwatch.com/')
elif a=='tell me a joke':
joke()
elif a=='open Google sheets':
webbrowser.open("https://docs.google.com/")
elif a=="show Bitcoin details":
webbrowser.open("https://bitcoin.org/en/")
elif a=="open currency converter":
webbrowser.open('https://www.xe.com/currencyconverter/')
elif a=='show trending':
webbrowser.open('https://trends.google.com/')
elif a=='show public holiday information':
webbrowser.open('https://www.fairwork.gov.au/')
elif a=='show Wi-Fi network details':
webbrowser.open('https://wifi-password-
show.en.uptodown.com/')
elif a=="open calendar": #hari
webbrowser.open('https://calendar.google.com/calendar/r')
elif a=="open movies" or a=='Open series':
webbrowser.open('https://soap2day.to/')
elif a=="open alarm":
webbrowser.open('https://kukuklok.com/')
elif a=="open calculator" :
webbrowser.open('https://www.calculator.net/')
Output:
Output- “Exiting Project ’!!!’ You are a
proud user of Buddy 2.0!!!. Thanks for
using Buddy, your perfect virtual
assistant (given out in the form of
voice).
Help:
Input: ‘help’ given as voice input
Output:
Main options of the code are shown
which will be useful for the users to
navigate through the various menus.
converting voice to text:
INPUT:
Hi this is Hari Ram this is a testing
sample.
Output:
Exit menu
Input- ‘exit’ (input given in the form of
voice)
Pairing State
Tamil Nadu and Jammu & Kashmir are the
states that have been paired. Jammu &
Kashmir has a population of 1.25 crores
(or 12.5 million) in which almost 96 lakh
have a mobile phone subscription and 35
lakh people use internet. Of them we can
assume at least 10 lakh people are using
virtual assistants (on a global average).
Tamil Nadu has a population of 8.37 crore
(or 83.7 million) of which 4.2 crore (or 42
million) people have an internet
connection and 7.2 crore ( 72 million)
people have an cellular connection. This
stark contrast in usage ratio is due to the
mountainous and hilly terrain of Jammu &
Kashmir and the contrasting planar terrain
of Tamil Nadu.
FUTURE SCOPE
In future we have planned to add
regional language(s) to give voice
command(s), so that many people
around the world can access our service.
In future we have also planned to make
our assistant, a cross platform
application.
The upcoming update of BUDDY will be
working with 3-Dimensional pictures.
In future we are sure that we will be
introducing different characters with
their own features. Users can modify
their own assistant.
In future buddy will be able to read out
the notification(s) in the device.
BIBLIOGRAPHY
A Byte of Python
-C.H.SWAPOOR
PYTHON PROGRAMMING
-JOHN M.ZELC
DIVE INTO PYTHON
-MARK PILGRIMS
INTODUCTION TO PYTHON
-SUMITA ARORA
PYTHON BASICS
-GOYAL BROTHERS