-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
152 lines (121 loc) · 4.23 KB
/
main.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
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
import os
import pyttsx3
import speech_recognition as sr
import datetime
import cv2
import wikipedia
from requests import get
import webbrowser
import pywhatkit
import time
import sys
import pyjokes
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voices',voices[0].id)
def speak(audio):
engine.say(audio)
print(audio)
engine.runAndWait()
#text to speach
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source, timeout=5, phrase_time_limit=8)
try:
print("Recognising...")
query = r.recognize_google(audio, language='en-us')
print(f"user said: {query}")
except Exception as e:
print("some thing went worng..")
return "none"
return query
def wish():
speak("Welcome back sir")
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<=12:
speak("Good morning ")
elif hour>12 and hour<=18:
speak("good afternoon")
elif hour>18 and hour<=24:
speak("good evening ")
else:
speak("good Night")
speak("how can i help you ")
def date():
day = int(datetime.datetime.now().day)
month = int(datetime.datetime.now().month)
year = int(datetime.datetime.now().year)
speak("The current date is")
print(day, month, year)
speak(day)
speak(month)
speak(year)
def time():
time = datetime.datetime.now().strftime("%H:%M:%S")
speak(time)
print(time)
def whatsap():
speak("Ok sir, tell me the number")
spoken_number = takeCommand().lower()
print(spoken_number)
length = len(spoken_number)
if length != 0 and length == 12:
speak("what should i message")
code = "+91"
number_nospace = spoken_number.replace(" ","")
numb = code + number_nospace
print(numb)
message = takeCommand().lower()
hour = int(datetime.datetime.now().hour)
min = int(datetime.datetime.now().minute)
time_what = min + 1
pywhatkit.sendwhatmsg(numb, message, hour , time_what)
time.sleep(120)
else:
speak("oh there was some problem pls try again late")
whatsap()
if __name__ == "__main__":
while True:
query = takeCommand().lower()
if "open notepad" in query:
npath = "C:\\Windows\\notepad.exe"
os.startfile(npath)
elif "open camera" in query:
cap = cv2.VideoCapture(0)
while True:
ret, img = cap.read()
cv2.imshow('webcam', img)
k = cv2.waitKey(50)
if k == 27:
break
cap.release()
elif "time" in query:
time()
elif "date" in query:
date()
elif "hello jarvis" in query:
wish()
elif "wikipedia" in query:
speak("Searching wikipedia ...")
query = query.replace("wikipedia", "")
result = wikipedia.summary(query, sentences=2)
speak("According to wikipedia")
speak(result)
print(result)
elif "IP address" in query:
ip = get('https://api.ipify.org/').text
speak = (f"your ip address is {ip}")
elif "whatsapp" in query:
whatsap()
elif "bye jarvis" in query:
speak("bye sir see you again. Have a good day")
sys.exit()
elif "close notepad" in query:
speak("closing notepad")
os.system("taskkill /f /im notepad.exe")
elif "tell me a joke" in query:
joke = pyjokes.get_joke()
speak(joke)