-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathcode.py
More file actions
159 lines (137 loc) · 4.6 KB
/
code.py
File metadata and controls
159 lines (137 loc) · 4.6 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import pyjokes
import wikipedia
from datetime import datetime
from geopy.geocoders import Nominatim
import os
import psutil
from bs4 import BeautifulSoup
import requests
listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
def talk(text):
engine.say(text)
engine.runAndWait()
hi = 0
if hi == 0:
talk('hello iam kkavi')
print('hello iam kavi Voice assistant')
talk('How are you buddy!!!')
print('How are you buddy!!!')
talk('doing good right?????')
print('doing good right?????')
talk('think so good')
print('think so good')
talk('what can i do for you buddy')
print('what can i do for you buddy')
else:
print('listening')
def take_command():
try:
with sr.Microphone() as source:
talk('listening.....')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'kavi' in command:
command = command.replace('kavi', '')
print(command)
except:
pass
return command
def run_kavi():
command = take_command()
print(command)
if 'play' in command:
talk('playing')
print('playing')
song = command.replace('play', '')
talk('playing ' + song)
pywhatkit.playonyt(song)
elif 'whatsapp' in command:
pywhatkit.sendwhatmsg("+91 93611 40968", "hello iam kavi,my boss has told me to text any important info",
13, 58)
print("Successfully Sent!")
elif 'who is' in command:
person = command.replace('who is', '')
source = wikipedia.summary(person, 100)
print(source)
talk(source)
elif 'search' in command:
info = command.replace('search', '')
general = wikipedia.search(info, 100)
print(general)
talk(general)
elif 'history' in command:
gen = command.replace('history, battle, movie review', '')
small = wikipedia.summary(gen, 100)
print(small)
talk(small)
elif 'health' in command:
load1, load5, load15 = psutil.getloadavg()
cpu_usage = (load15 / os.cpu_count()) * 100
cd = ("My health was in good condition because your'e using me in good way (cpu usage) : ", cpu_usage)
talk(cd)
elif 'memory' in command:
bc = (psutil.virtual_memory()[2])
talk(bc)
elif 'location' in command:
loc = Nominatim(user_agent="GetLoc")
getloc = loc.geocode("Coimbatore")
print(getloc.address)
talk(getloc)
elif 'weather' in command:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
def weather(city):
city = city.replace(" ", "+")
res = requests.get(
f'https://www.google.com/search?q={city}&oq={city}&aqs=chrome.0.35i39l2j0l4j46j69i60.6128j1j7&sourceid=chrome&ie=UTF-8',
headers=headers)
print("Searching...\n")
soup = BeautifulSoup(res.text, 'html.parser')
location = soup.select('#wob_loc')[0].getText().strip()
time = soup.select('#wob_dts')[0].getText().strip()
info = soup.select('#wob_dc')[0].getText().strip()
weather = soup.select('#wob_tm')[0].getText().strip()
print(location)
talk(location)
print(info)
talk(info)
print(time)
talk(time)
ab = (weather + "°C")
talk(ab)
print(ab)
city1 = "coimbatore"
talk(city1)
city = city1 + " weather"
weather(city)
abc = ("Have a Nice Day Buddy")
talk(abc)
elif 'movie review' in command:
movie = command.replace('movie review', '')
small = wikipedia.summary(movie, 10)
print(small)
talk(small)
elif 'are you single' in command:
talk('no......um.i am in relationship with wireless devices')
elif 'do you like me' in command:
talk('yes boss definitely')
elif 'what is your name' in command:
talk('My devloper karunakran has named me kkavi')
elif 'cringe' in command:
talk('alright........he/she was funniest perosn')
elif 'joke' in command:
joke = pyjokes.get_joke()
print(joke)
talk(joke)
else:
talk('cant get it....please say it again')
while True:
run_kavi()