forked from theMAChackers/GUI-Jarvis
/
run.py
119 lines (105 loc) · 3.75 KB
/
run.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
from PyQt5 import QtWidgets, QtGui,QtCore
from PyQt5.QtGui import QMovie
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.uic import loadUiType
import pyttsx3
import speech_recognition as sr
import os
import time
import webbrowser
import datetime
import subprocess
flags = QtCore.Qt.WindowFlags(QtCore.Qt.FramelessWindowHint)
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[1].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wish():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour <12:
speak("Good morning")
elif hour>=12 and hour<18:
speak("Good Afternoon")
else:
speak("Good night")
class mainT(QThread):
def __init__(self):
super(mainT,self).__init__()
def run(self):
self.JARVIS()
def STT(self):
R = sr.Recognizer()
with sr.Microphone() as source:
speak("Listning")
audio = R.listen(source)
try:
print("Recog......")
speak("initializing")
text = R.recognize_google(audio,language='en-in')
print(">> ",text)
except Exception:
speak("Sorry Speak Again")
return "None"
text = text.lower()
return text
def JARVIS(self):
speak("Please wait system initializing.")
speak("Loading disks, security checkup")
speak("Launching user interface")
wish()
while True:
self.query = self.STT()
if 'goodbye' in self.query:
exit()
elif 'who made you' in self.query:
speak("I was designed by my team members on vs code")
elif 'are you a male or female' in self.query:
speak("I don't think we have time for this")
elif 'open google' in self.query:
webbrowser.open('www.google.co.in')
speak("opening google")
elif 'open youtube' in self.query:
webbrowser.open("www.youtube.com")
speak(" opening youtube" )
elif 'open stackoverflow' in self.query:
webbrowser.open("stackoverflow.com")
speak("opening stackoverflow")
elif 'open spotify' in self.query:
sPath = "C:\\Users\\Haris\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
os.startfile(sPath)
elif ' open calculator' in self.query:
subprocess.open('calc.exe')
elif 'tell me the time' in self.query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak("Sir, the time is")
speak(strTime)
elif 'play music' in self.query:
speak("playing music from pc")
self.music_dir ="./music"
self.musics = os.listdir(self.music_dir)
os.startfile(os.path.join(self.music_dir,self.musics[0]))
FROM_MAIN,_ = loadUiType(os.path.join(os.path.dirname(__file__),"./scifi.ui"))
class Main(QMainWindow,FROM_MAIN):
def __init__(self,parent=None):
super(Main,self).__init__(parent)
self.setupUi(self)
self.setFixedSize(1920,1080)
self.label_7 = QLabel
self.setWindowFlags(flags)
Dspeak = mainT()
self.label_7 = QMovie("./lib/gifloader.gif", QByteArray(), self)
self.label_7.setCacheMode(QMovie.CacheAll)
self.label_4.setMovie(self.label_7)
self.label_7.start()
self.ts = time.strftime("%A, %d %B")
Dspeak.start()
self.label.setPixmap(QPixmap("./lib/tuse.jpg"))
app = QtWidgets.QApplication(sys.argv)
main = Main()
main.show()
exit(app.exec_())