-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrun.py
114 lines (89 loc) · 3.12 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
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
flags = QtCore.Qt.WindowFlags(QtCore.Qt.FramelessWindowHint)
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[0].id)
engine.setProperty('rate',180)
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:
print("Listning...........")
audio = R.listen(source)
try:
print("Recog......")
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):
wish()
while True:
self.query = self.STT()
if 'good bye' in self.query:
sys.exit()
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")
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.exitB.setStyleSheet("background-image:url(./lib/exit - Copy.png);\n"
"border:none;")
self.exitB.clicked.connect(self.close)
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.png"))
self.label_5.setText("<font size=8 color='white'>"+self.ts+"</font>")
self.label_5.setFont(QFont(QFont('Acens',8)))
app = QtWidgets.QApplication(sys.argv)
main = Main()
main.show()
exit(app.exec_())