|
| 1 | +from email.mime import audio |
| 2 | +from importlib.resources import path |
| 3 | +from logging import exception |
| 4 | +from random import Random, random |
| 5 | +from re import S |
| 6 | +import sys |
| 7 | +from typing_extensions import Self |
| 8 | +import pyttsx3 |
| 9 | +import speech_recognition as sr |
| 10 | +import datetime |
| 11 | +import os |
| 12 | +import cv2 |
| 13 | +import random |
| 14 | +from requests import get |
| 15 | +import wikipedia |
| 16 | +import webbrowser |
| 17 | +import pywhatkit as kit |
| 18 | +import smtplib |
| 19 | +import sys |
| 20 | +import pyjokes |
| 21 | +from PyQt5 import QtWidgets, QtCore, QtGui |
| 22 | +from PyQt5.QtCore import QTimer, QTime, QDate, Qt |
| 23 | +from PyQt5.QtGui import QMovie |
| 24 | +from PyQt5.QtCore import * |
| 25 | +from PyQt5.QtGui import * |
| 26 | +from PyQt5.QtWidgets import * |
| 27 | +from PyQt5.uic import loadUiType |
| 28 | +from jarvisUi import Ui_jarvisUi |
| 29 | + |
| 30 | + |
| 31 | +engine = pyttsx3.init('sapi5') |
| 32 | +voices = engine.getProperty('voices') |
| 33 | +print(voices[0].id) |
| 34 | +engine.setProperty('voices', voices[0].id) |
| 35 | + |
| 36 | + |
| 37 | +# text to speech |
| 38 | +def speak(audio): |
| 39 | + engine.say(audio) |
| 40 | + print(audio) |
| 41 | + engine.runAndWait() |
| 42 | + |
| 43 | + |
| 44 | +# wish function |
| 45 | +def wish(): |
| 46 | + hour = int(datetime.datetime.now().hour) |
| 47 | + #tt = time.strftime("%I:%M:%p") |
| 48 | + |
| 49 | + if hour >= 0 and hour <= 12: |
| 50 | + speak("Good morning,sir") |
| 51 | + elif hour > 12 and hour < 18: |
| 52 | + speak("Good afternoon,sir") |
| 53 | + else: |
| 54 | + speak("Good Evening,sir") |
| 55 | + speak("I am Jarvis sir,How can I help you?") |
| 56 | + |
| 57 | + |
| 58 | +# to define send email |
| 59 | +def sendEmail(to, content): |
| 60 | + server = smtplib.SMTP('smtp.gmail.com', 587) |
| 61 | + server.ehlo() |
| 62 | + server.starttls() |
| 63 | + server. login( '[email protected]', 'Tata@1234') |
| 64 | + server. sendmail( '[email protected]', to, content) |
| 65 | + server.close() |
| 66 | + |
| 67 | +# to convert voice into text |
| 68 | +class Mainthread(QThread): |
| 69 | + def __init__(self): |
| 70 | + super(Mainthread,self).__init__() |
| 71 | + |
| 72 | + def run(self): |
| 73 | + self.TaskExecution() |
| 74 | + |
| 75 | + def takecommand(self): |
| 76 | + |
| 77 | + r = sr.Recognizer() |
| 78 | + with sr.Microphone() as source: |
| 79 | + print("Listening...") |
| 80 | + r.pause_threshold = 1 |
| 81 | + r.adjust_for_ambient_noise(source) |
| 82 | + audio = r.listen(source, timeout=2, phrase_time_limit=5) |
| 83 | + |
| 84 | + try: |
| 85 | + print("Recognizng..") |
| 86 | + query = r.recognize_google(audio, language='en-in') |
| 87 | + print(f"user said: {query}") |
| 88 | + |
| 89 | + except exception as e: |
| 90 | + speak("could you please repeat...") |
| 91 | + return "none" |
| 92 | + query = query.lower() |
| 93 | + return query |
| 94 | + |
| 95 | + #if __name__ == "__main__": |
| 96 | + def TaskExecution(self): |
| 97 | + #def start(): |
| 98 | + wish() |
| 99 | + |
| 100 | + while True: |
| 101 | + |
| 102 | + self.query = self.takecommand() |
| 103 | + |
| 104 | + # logic building for tasks |
| 105 | + |
| 106 | + if "open notepad" in self.query: |
| 107 | + npath = "C:\\Windows\\System32\\notepad.exe" |
| 108 | + os.startfile(npath) |
| 109 | + |
| 110 | + elif "open adobe reader" in self.query: |
| 111 | + apath = "C:\\Program Files (x86)\\Adobe\\Reader 10.0\\Reader\\AcroRd32.exe" |
| 112 | + os.startfile(apath) |
| 113 | + |
| 114 | + elif "open command prompt" in self.query: |
| 115 | + os.system("start cmd") |
| 116 | + |
| 117 | + elif "open camera" in self.query: |
| 118 | + cap = cv2.VideoCapture(0) |
| 119 | + while True: |
| 120 | + ret, img = cap.read() |
| 121 | + cv2.inshow('webcam', img) |
| 122 | + k = cv2.waitKey(50) |
| 123 | + if k == 27: |
| 124 | + break |
| 125 | + cap.release() |
| 126 | + cv2.destroyAllWindows() |
| 127 | + |
| 128 | + elif "play music" in self.query: |
| 129 | + music_dir = "C:\\Users\\vijay\\Music" |
| 130 | + songs = os.listdir(music_dir) |
| 131 | + rd = Random.choice(songs) |
| 132 | + # for song in songs: |
| 133 | + # if song.endswith('.mp3'): |
| 134 | + os.startfile(os.path.join(music_dir, rd)) |
| 135 | + # os.startfile(os.path.join(music_dir,song)) |
| 136 | + |
| 137 | + elif "ip address" in self.query: |
| 138 | + ip = get('https://api.ipify.org').text |
| 139 | + speak(f"your IP Address is {ip}") |
| 140 | + |
| 141 | + elif "wikipedia" in self.query: |
| 142 | + speak("Searching wikipedia...") |
| 143 | + query = query.replace("wikipedia", "") |
| 144 | + result = wikipedia.summary(query, sentence=2) |
| 145 | + speak("According to wikipedia") |
| 146 | + speak(result) |
| 147 | + # print(result) |
| 148 | + |
| 149 | + elif "open youtube" in self.query: |
| 150 | + webbrowser.open("www.youtube.com") |
| 151 | + |
| 152 | + elif "open facebook" in self.query: |
| 153 | + webbrowser.open("www.facebook.com") |
| 154 | + |
| 155 | + elif "open stack overflow" in self.query: |
| 156 | + webbrowser.open("www.stackoverflow.com") |
| 157 | + |
| 158 | + elif "open google" in self.query: |
| 159 | + # to search something specific on google |
| 160 | + speak("Sir what should i search on google") |
| 161 | + cm = self.takecommand() |
| 162 | + webbrowser.open(f"{cm}") |
| 163 | + |
| 164 | + elif "send message" in self.query: |
| 165 | + #speak("Sir,to whom should i send message") |
| 166 | + #wmsg = takecommand().lower() |
| 167 | + # 2.25 is time at which you send |
| 168 | + kit.sendwhatmsg("+919920309439", "this is a testing message", 2.25) |
| 169 | + |
| 170 | + elif "play songs on youtube" in self.query: |
| 171 | + speak("Sir what should i play on youtube") |
| 172 | + play = self.takecommand() |
| 173 | + kit.playonyt(f"{play}") |
| 174 | + |
| 175 | + elif "send email" in self.query: |
| 176 | + try: |
| 177 | + speak("what should i say?") |
| 178 | + content = self.takecommand() |
| 179 | + |
| 180 | + sendEmail(to, content) |
| 181 | + speak("Email has been sent") |
| 182 | + |
| 183 | + except exception as e: |
| 184 | + print(e) |
| 185 | + speak("sorry sir, i am not able to send the email") |
| 186 | + |
| 187 | + # to close application |
| 188 | + elif "close notepad" in self.query: |
| 189 | + speak("okay sir,closing notepad") |
| 190 | + os.system("taskkill /f/im notepad.exe") |
| 191 | + |
| 192 | + elif "set alarm" in self.query: |
| 193 | + nn = int(datetime.datetime.now().hour) |
| 194 | + if nn == 11: |
| 195 | + music_dir = "Libraries\\Music" |
| 196 | + songs = os.listdir(music_dir) |
| 197 | + os.startfile(os.path.join(music_dir, songs[0])) |
| 198 | + |
| 199 | + elif "joke" in self.query: |
| 200 | + joke = pyjokes.get_joke() |
| 201 | + speak(joke) |
| 202 | + |
| 203 | + elif "shutdown the system" in self.query: |
| 204 | + os.system("shutdown /s /t 5") |
| 205 | + |
| 206 | + elif "restart the system" in self.query: |
| 207 | + os.system("shutdown /r /t 5") |
| 208 | + |
| 209 | + elif "sleep the system" in self.query: |
| 210 | + os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0") |
| 211 | + |
| 212 | + elif "thank you" in self.query: |
| 213 | + speak("thankyou sir,have a good day") |
| 214 | + sys.exit() |
| 215 | + |
| 216 | + speak("sir,do you have any other work") |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | +#if __name__ == "__main__" : |
| 221 | +# TaskExecution() |
| 222 | + |
| 223 | +startExecution = Mainthread() |
| 224 | + |
| 225 | +class Main(QMainWindow): |
| 226 | + def __init__(self): |
| 227 | + super().__init__() |
| 228 | + self.ui = Ui_jarvisUi() |
| 229 | + self.ui.setupUi(self) |
| 230 | + self.ui.pushButton.clicked.connect(self.startTask) |
| 231 | + self.ui.pushButton_2.clicked.connect(self.close) |
| 232 | + |
| 233 | + def startTask(self): |
| 234 | + #self.ui.movie = QtGui.QMovie("Black_Template.jpg") |
| 235 | + #self.ui.label.setMovie(self.ui.movie) |
| 236 | + #self.ui.movie.start() |
| 237 | + self.ui.movie = QtGui.QMovie("Iron_Template_1.gif") |
| 238 | + self.ui.label_2.setMovie(self.ui.movie) |
| 239 | + self.ui.movie.start() |
| 240 | + self.ui.movie = QtGui.QMovie("jarvis_jj.gif") |
| 241 | + self.ui.label_3.setMovie(self.ui.movie) |
| 242 | + self.ui.movie.start() |
| 243 | + self.ui.movie = QtGui.QMovie("initial.gif") |
| 244 | + self.ui.label_4.setMovie(self.ui.movie) |
| 245 | + self.ui.movie.start() |
| 246 | + self.ui.movie = QtGui.QMovie("Health_Template.gif") |
| 247 | + self.ui.label_5.setMovie(self.ui.movie) |
| 248 | + self.ui.movie.start() |
| 249 | + self.ui.movie = QtGui.QMovie("B.G_Template_1.gif") |
| 250 | + self.ui.label_6.setMovie(self.ui.movie) |
| 251 | + self.ui.movie.start() |
| 252 | + timer = QTimer(self) |
| 253 | + timer.timeout.connect(self.showTime) |
| 254 | + timer.start(1000) |
| 255 | + startExecution.start() |
| 256 | + |
| 257 | + def showTime(self): |
| 258 | + current_time = QTime.currentTime() |
| 259 | + current_date = QDate.currentDate() |
| 260 | + label_time = current_time.toString('hh:mm:ss') |
| 261 | + label_date = current_date.toString(Qt.ISODate) |
| 262 | + self.ui.textBrowser.setText(label_date) |
| 263 | + self.ui.textBrowser_2.setText(label_time) |
| 264 | + |
| 265 | + |
| 266 | + |
| 267 | +app = QApplication(sys.argv) |
| 268 | +jarvis = Main() |
| 269 | +jarvis.show() |
| 270 | +exit(app.exec_()) |
| 271 | + |
| 272 | + |
| 273 | + |
| 274 | + |
| 275 | + |
0 commit comments