Repository navigation
Expand file tree
/
Copy pathVeronica.py
More file actions
116 lines (86 loc) · 3.15 KB
/
Copy pathVeronica.py
File metadata and controls
116 lines (86 loc) · 3.15 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
import pyttsx3
# import pyaudio
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser
import os
import random
#-----------------------------------------------------
engine=pyttsx3.init('sapi5')
#===========================
''' set voice type '''
voices=engine.getProperty("voices")
engine.setProperty("voice",voices[1].id)
#********************************************
''' set rate '''
rate=engine.getProperty("rate")
engine.setProperty("rate",170)
#-------------------------------------------------------------------------------------
''' functions '''
def speak(audio):
''' this function will let your virtual assisstant speak '''
engine.say(audio)
engine.runAndWait()
#********************************************************************
def wishme():
''' this function help to wish the user '''
hour=int(datetime.datetime.now().hour)
if 0<hour<12:
speak('Good Morning Omnish Sir')
elif 12<=hour<17:
speak('good afternoon Omnish Sir')
else:
speak('good evening Omnish Sir')
speak('I am Veronica, virtual assisstant of this system, how may I help you')
#******************************************************************************************
def takecommand():
''' it takes user voice input via microphone and gives a string as output '''
r=sr.Recognizer()
with sr.Microphone() as source:
print('Listining........')
r.pause_threshold=1
r.energy_threshold=500
r.adjust_for_ambient_noise(source, duration=0.5)
audio=r.listen(source)
print('Listining completed')
try:
print('Recognizing')
query=r.recognize_google(audio,language='en-in')
print(f'you said: {query}\n')
# print(type(audio))
except Exception:
print('say that again please.....')
return 'None'
return query
#------------------------------------------------------------------------
if __name__ == "__main__":
# print(sr.Microphone.list_microphone_names())
wishme()
while True:
q=takecommand().lower()
''' functions based on input commands '''
if 'wikipedia' in q:
speak('searching wikipedia...')
searching_item=q.replace('wikipedia','')
results=wikipedia.summary(searching_item)
speak(results)
elif 'open youtube' in q:
webbrowser.open('youtube.com')
elif 'open google' in q:
webbrowser.open('google.com')
elif 'open stackoverflow' in q:
webbrowser.open('stackoverflow.com')
elif 'open anime' in q:
webbrowser.open('www1.9anime.to')
elif 'play music' in q:
song_no=random.randrange(0,111,1)
file='F:\\MP3 Songs\\KK'
songs=os.listdir(file)
os.startfile(os.path.join(file,songs[song_no]))
elif 'time' in q:
time=datetime.datetime.now().strftime("%H %M")
speak(time)
elif 'open notepad' in q:
file_path="C:\\Users\\MY LENOVO\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Accessories\\Notepad"
os.startfile(file_path)