forked from prathimacode-hub/Awesome_Python_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWiki_Bot.py
82 lines (72 loc) · 2.63 KB
/
Wiki_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
import pyttsx3 as py #Text to speech Library
import datetime #Date & Time Library
import speech_recognition as sr #Speech recognition
import wikipedia #Wikipedia Library
import urllib.request #URL Library
import os #Operating System Library
import pyaudio #Audio Library
------------ #Intialization -----------
engine = py.init('sapi5')
engine.setProperty('rate', 150)
voices = engine.getProperty('voices')
engine.setProperty('voices',voices[0].id)
def speak(audio): #Audio Output
engine.say(audio)
engine.runAndWait()
def wishme(): #Greetings
hour =int(datetime.datetime.now().hour)
if(hour>=0 and hour<12):
speak("Good Morning!, Durga Sai ")
elif(hour>=12 and hour<18):
speak("Good Afternoon, Durga Sai ")
else:
speak("Good Evening, Durga Sai")
speak("Im wiki bot how may i help you today")
---------------- #Navigation ---------------
def navigate():
r= sr.Recognizer() #Speech
with sr.Microphone() as source:
print("Tell me what you want to search on wikipedia ?")
r.pause_threshold=1
audio = r.listen(source) #To listen (input)
try:
print("Please Wait sir, Search in progress...")
result = r.recognize_google(audio,language='en-in')
print(f"You said:{result}\n") #Confirmation
speak(result) #Output
except Exception as e: #Exceptions
return "None"
return result
def image(query): #Relevant Image from Wiki
query = query.replace(" ","_".lower())
page_image = wikipedia.page(query)
image_down_link = page_image.images[5]
urllib.request.urlretrieve(image_down_link , "loc.jpg")
os.startfile("loc.jpg") #Image display
if __name__ == '__main__':
wishme()
query = navigate().lower()
if "wikipedia " in query:
speak("searching in wiki hang on...!")
query = query.replace("wikipedia ","")
result =wikipedia.summary(query,sentences=2)
image(query)
speak("According to wiki..")
page_image = wikipedia.page(query)
image_down_link = page_image.images[0]
urllib.request.urlretrieve(image_down_link , "loc.jpg")
print(result)
speak(result) #Output
elif '' in query:
try:
speak("searching in wiki hang on...!")
query = query.replace("","")
result =wikipedia.summary(query,sentences=3)
speak("According to wiki..") #Result found
print(result)
image(query)
speak(result)
except Exception as e:
speak("Im sorry i could not found your query") #No result
else:
speak("Im sorry i could not found your query")#No result