-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDesktop_Assistent.py
More file actions
173 lines (129 loc) · 5.4 KB
/
Desktop_Assistent.py
File metadata and controls
173 lines (129 loc) · 5.4 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import speech_recognition as sr
import pyttsx3
import webbrowser
import datetime
import wikipediaapi
import pywhatkit
import os
def speech_to_text():
# Initialize the recognizer
recognizer = sr.Recognizer()
# Use the default microphone as the audio source
with sr.Microphone() as source:
recognizer.adjust_for_ambient_noise(source)
text_to_speech("iam listining....")
audio = recognizer.listen(source)
try:
text = recognizer.recognize_google(audio)
return text.lower()
except sr.UnknownValueError:
text_to_speech("Sorry, could not understand audio.")
return 0
except sr.RequestError as e:
text_to_speech("Could not request results from Google Speech Recognition service; {0}".format(e))
return 0
def text_to_speech(text):
# Initialize the TTS engine
engine = pyttsx3.init()
# Set properties (optional)
# You can set properties like the rate (speed) and volume
engine.setProperty('rate', 150) # Speed of speech
engine.setProperty('volume', 1.0) # Volume level (0.0 to 1.0)
# Convert the text to speech
engine.say(text)
# Wait for the speech to finish
engine.runAndWait()
def remove(command):
element = ['what is','who is','open','.com','please','play','can','you','website','for me','search','for', ' ']
for x in element:
if x in command:
command = command.replace(x, '')
return command
def data_time(command):
if 'time' in command:
current_time = datetime.datetime.now().time()
time = current_time.strftime("%#I %#M %p")
text_to_speech("current time is"+time)
if 'date' in command:
current_date = datetime.date.today()
date= current_date.strftime("%A, %#d %B %Y")
text_to_speech(date)
def get_wikipedia_summary(query, lang='english'):
query = remove(query)
wiki_wiki = wikipediaapi.Wikipedia(lang)
page_py = wiki_wiki.page(query)
if not page_py.exists():
text_to_speech(f"Page '{query}' does not exist on Wikipedia.")
pywhatkit.search(query)
text = page_py.summary[:500]
text_to_speech(text)
def check_sysApps(command):
applications = ['notepad.exe', 'calc.exe', 'explorer.exe', 'control.exe', 'taskmgr.exe', 'cmd.exe',
'powershell.exe', 'regedit.exe', 'devmgmt.msc', 'services.msc', 'compmgmt.msc',
'diskmgmt.msc', 'mspaint.exe', 'wordpad.exe', 'msconfig.exe', 'notepad++.exe',
'chrome.exe', 'iexplore.exe', 'outlook.exe', 'winword.exe', 'excel.exe', 'powerpnt.exe',
'code.exe', 'skype.exe' , 'zoom.exe', 'teams.exe']
app_names=['notepad', 'calculator', 'fileexplorer', 'controlpanel', 'taskmanager', 'commandpromptcmd',
'powershell', 'registryeditor', 'devicemanager', 'services', 'computermanagement',
'diskmanagement', 'mspaint', 'wordpad', 'systemconfiguration', 'notepad++', 'chrome',
'internetexplorer', 'microsoftoutlook(msoutkook)', 'word', 'excel',
'powerpoint', 'visualstudiocodevscode', 'skype', 'zoom', 'teams']
command = remove(command)
print(command)
for x in range(len(app_names)):
if command in app_names[x] or app_names[x] in command:
if command =='':
text_to_speech("please tell the application name to be open")
return True
print("validated",app_names[x],' ',applications[x])
open_application(applications[x])
return True
return False
def open_application(application_path):
try:
# Using os.system to open the application
text_to_speech("Opening Your Application")
os.system('start '+application_path)
except FileNotFoundError:
text_to_speech(f"Error: Application not found at {application_path}")
except Exception as e:
text_to_speech(f"An unexpected error occurred: {e}")
def open_website(command):
command = remove(command)
url = 'www.'+command+'.com'
url= url.replace(' ', '')
print(url)
webbrowser.open(url)
def play(command):
try:
pywhatkit.playonyt(command)
text_to_speech("Playing..."+command)
except:
text_to_speech("Network Error Occurred try again...")
if __name__ == '__main__':
a=0
while True:
if a==0:
text_to_speech("hello boss welcome! back.." )
a+=1
command = speech_to_text()
if command==0:
continue
elif 'exit' in command or 'close' in command:
text_to_speech("Good bye, see you again")
break
elif 'date' in command or 'time' in command:
data_time(command)
elif 'who is' in command or 'what is' in command:
get_wikipedia_summary(command)
elif 'open' in command:
if not (check_sysApps(command)):
open_website(command)
elif 'play' in command:
command = remove(command)
play(command)
elif 'search' in command:
command = remove(command)
pywhatkit.search(command)
else:
text_to_speech(' sorry i dont understand you commands')