-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBot.py
112 lines (94 loc) · 3.62 KB
/
Bot.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
import wikipedia
import speech_recognition as sr
from GoogleNews import GoogleNews
import pyttsx3
from datetime import date
import datetime
import pyjokes
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
# wishme (regular greetings according to the time )
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wish():
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour <= 12:
speak(f"good morning ayaan")
elif hour >= 12 and hour <= 18:
speak(f"good afternoon ayaan")
else:
speak(f"good evening ayaan")
# voice input
def takeCommand():
r = sr.Recognizer()
with sr.Microphone(device_index=1) as source:
print("listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}\n")
except Exception as e:
print("Say that again please...")
return "None"
return query
wish()
while True:
query = takeCommand().lower()
# search/order_commands
if "hi sohan" in query or "hello sohan" in query:
speak("hi ayaan")
elif "how are you sohan" in query:
speak("great ayaan")
elif "thank you sohan" in query:
speak("welcome ayaan")
elif "good evening sohan" in query or "good morning sohan" in query or "good afternoon sohan" in query:
wish = query
wish = wish.replace("sohan", "")
speak(wish)
elif 'sohan can you tell me a joke' in query:
s = pyjokes.get_joke(language='en', category='all')
speak(s)
elif "sohan what" in query or "sohan who" in query or "sohan how" in query:
speak('one second ayaan')
query = query
query = query.replace("sohan", "")
result = wikipedia.summary(query, sentences=2)
speak("ayaan"+result)
elif "sohan" in query:
speak('Yes ayaan...')
query = takeCommand()
result = wikipedia.summary(query, sentences=2)
speak("ayaan"+result)
#test
# if "hi sohan" in query or "hello sohan" in query:
# speak("hi ayaan")
# query = query
# if "how are you" in query:
# speak("great ayaan")
# elif "thank you" in query:
# speak("welcome ayaan")
# elif "good evening" in query or "good morning" in query or "good afternoon" in query:
# wish = query
# wish = wish.replace("sohan", "")
# speak(wish)
# elif 'sohan can you tell me a joke' in query:
# s = pyjokes.get_joke(language='en', category='all')
# speak(s)
# elif "sohan what" in query or "sohan who" in query:
# speak('one second ayaan')
# query = query
# query = query.replace("sohan", "")
# result = wikipedia.summary(query, sentences=2)
# speak("ayaan"+result)
# elif "sohan" in query:
# speak('Yes ayaan...')
# query = takeCommand()
# result = wikipedia.summary(query, sentences=2)
# speak("ayaan"+result)
# else:
# pass
#test