-
Notifications
You must be signed in to change notification settings - Fork 0
/
Connect.py
115 lines (91 loc) · 3.64 KB
/
Connect.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#Importing Modules
import speech_recognition as sr import pyttsx3
import datetime import wikipedia import webbrowser import os
#Linking Voice recognizer
listener = sr.Recognizer() engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices') engine.setProperty('voice', voices[1].id)
#Definig function for taking command from user
def take_command():
try:
with sr.Microphone() as source:
print('listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice, language='en-in') command = command.lower()
if 'hey connect' in command:
command = command.replace('hey connect', '') print(command)
print("Recognizing...")
except:
print("Can't Recognize, Check your internet connection and try again") return connect()
return command
#Defining function to calculate BMI
def bmi():
weight = int(input("Weight = "))
talk("Enter your weight")
height = int(input("Height = "))
talk("Enter your height")
bmi = weight / (height**2)
print("The BMI is " + bmi)
if bmi<18 :
talk("You are Underweight") print("Underweight")
elif bmi>=18 and bmi<24: talk("You are healthy")
print("Healthy")
elif bmi>=24 and bmi<30: talk("You are overweight")
print("Overweight")
elif bmi>=30:
talk("You are suffering from Obesity")
print("Suffering from Obesity")
#Defing function for welcome speech
def welcome():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
talk("Hey whatsapp, Good Morning!")
elif hour>=12 and hour<18:
talk("Hey whatsapp, Good Afternoon!")
else:
talk("Hey whatsapp, Good Evening!")
talk("I am your assistant, my name is connect. how may I help you")
#Defing function for voice output
def talk(text):
engine.say(text)
engine.runAndWait()
def connect():
command = take_command()
print("Command = " + command)
if 'time' in command:
timeA = datetime.datetime.now().strftime('%I:%M %p') talk('Current time is ' + timeA)
print("12 Hrs format = " + timeA)
timeB = datetime.datetime.now().strftime("%H:%M:%S") talk("and its " + timeB)
print("24 Hrs format = " + timeB)
elif 'hi connect' in command:
welcome()
elif 'what is' in command:
person = command.replace('what is', '')
info = wikipedia.summary(person, 1)
print(info)
talk(info)
elif 'about' in command:
person = command.replace('about', '')
info = wikipedia.summary(person, 1)
print(info)
talk(info)
elif 'are you single' in command:
talk('I am in a relationship with wifi')
elif 'bmi' in command:
talk("You we go")
print("Enter following details:")
bmi()
elif 'open youtube' in command:
talk("opening youtube")
webbrowser.open("https://youtube.com")
elif 'open word' in command:
codepath = "C:\\Program Files\\Microsoft Office\\root\\Office16\\WINWORD.EXE"
os.startfile(codepath)
elif 'open moodle' in command:
talk("opening college moodle on chrome")
webbrowser.open("https://fe.ges-coengg.org/login/index.php")
else:
talk('This command has not supported, I am in developing condition, you can try "about Salman khan"')
print('This command has not supported, I am in developing condition, you can try "about Salman khan"')
talk('I hope you are enjoying')
while True:
connect()