Skip to content

Commit 452895e

Browse files
Merge pull request prathimacode-hub#919 from DurgaSai-16/main
Wiki Bot
2 parents 838277a + f59d6d0 commit 452895e

File tree

7 files changed

+178
-0
lines changed

7 files changed

+178
-0
lines changed
Binary file not shown.
Binary file not shown.

AutomationScripts/Wiki Bot/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Wiki Bot🤖
2+
## Aim
3+
To create a Wikipedia Bot that listen our input, searches for output and reads it for us.
4+
## Purpose
5+
The purpose of Wikipedia Bot is to benefit user just by taking user's speech as input, searches for the topic and provides relevant output in the form of text as well as audio along with an image related to it.
6+
## Short Description
7+
- Bots are normally used to automate certain tasks, they can run without specific instructions from humans.
8+
- It'll be always nice to see something that makes our work simple,Instead searching for something in wikipedia by opening browser Wiki bot just asks what you want and gives all you want.
9+
- Wiki Bot is voice controlled bot that let's you to search and gather information within the Python IDE.
10+
- Wiki Bot browsesall the relevant information and speaks out about it briefly.
11+
- This also shows the related image of corresponding topic.
12+
- ***Libraries Imported:***
13+
- `wikipedia`
14+
- `datetime`
15+
- `pyttsx3`
16+
- `speech recoginition`
17+
- `pyaudio`
18+
- `urllib.request`
19+
- `os`
20+
21+
## Workflow
22+
23+
- Import all the required libraries i.e., wikipedia, datetime, pyttsx3, speech recognition, pyaudio, urllib.request, os.
24+
- `wikipedia`
25+
- ***Installation:*** `pip install wikipedia`
26+
- ***Purpose:*** This used acess wikipedia easily
27+
- `datetime`
28+
- ***Installation:*** It is Python's standard library.
29+
- ***Purpose:*** For greeting user based on the date and time
30+
- `pyttsx3`
31+
- ***Installation:*** `pip install pyttsx3`
32+
- ***Purpose:*** Converts text to speech.
33+
- `speech recoginition`
34+
- ***Installation:*** `pip install speechrecognition`
35+
- ***Purpose:*** Used to convert our voice input to text.
36+
- `pyaudio`
37+
- ***Installation:*** `pip install pyaudio`
38+
- ***Purpose:*** Used to speak out the information gathered by bot from the wikipedia
39+
- `urllib.request`
40+
- ***Installation:*** `pip3 install urllib3`
41+
- ***Purpose:*** Here it is used for fetching and opening URLs.
42+
- `os`
43+
- ***Installation:*** OS is python's standard library.
44+
- ***Purpose:*** This provides functions for creating and removing a directory, fetching its contents, changing and identifying the current directory, etc.
45+
- **NOTE:** [Python Extension Packages](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio)
46+
<ins>
47+
48+
</ins>
49+
50+
```
51+
52+
If you get any error while downloading and installing the required libraries
53+
Please visit above site and download whl file that supports your windows Version and then try to install it.
54+
```
55+
56+
57+
58+
## Compilation Steps
59+
- Download the file [Wiki_Bot.py](https://github.com/DurgaSai-16/Awesome_Python_Scripts/blob/main/AutomationScripts/Wiki%20Bot/Wiki_Bot.py)
60+
- Run the file [Wiki_Bot.py](https://github.com/DurgaSai-16/Awesome_Python_Scripts/blob/main/AutomationScripts/Wiki%20Bot/Wiki_Bot.py)
61+
- Execution of code begins and Asks the topic you want.
62+
- You need speak out the topic you
63+
- Then, starts searching the topic in wikipedia.
64+
- Gathers relevant information to the topic and starts dictation.
65+
- If it show any error regarding libraries, download them as mentioned in workflow.
66+
- If it didn't recognise your voice. Please try to speak clearly.
67+
68+
69+
## Output
70+
![WikiBot_Abdul Kalam](https://user-images.githubusercontent.com/85128689/127784305-15f32f0c-bf44-4bfa-8eb1-526b7f8d9fb9.png)
71+
72+
Image Pathlink: https://github.com/DurgaSai-16/Awesome_Python_Scripts/blob/main/AutomationScripts/Wiki%20Bot/Media/Images/Wiki_Bot%20Output_1.png
73+
74+
https://user-images.githubusercontent.com/85128689/127961763-46105dd0-82cf-432a-b58e-df493d844511.mp4
75+
76+
Video Pathlink: https://github.com/DurgaSai-16/Awesome_Python_Scripts/blob/main/AutomationScripts/Wiki%20Bot/Media/Videos/Wiki_Bot%20Output_1.mp4
77+
78+
![image](https://user-images.githubusercontent.com/85128689/127967178-cbe74819-01ba-4e61-819b-686f56842647.png)
79+
80+
81+
Image Pathlink: https://github.com/DurgaSai-16/Awesome_Python_Scripts/blob/main/AutomationScripts/Wiki%20Bot/Media/Images/Wiki_Bot%20Output_2.png
82+
83+
https://user-images.githubusercontent.com/85128689/127965524-b0dc2d77-d41b-4342-b103-1479cb7752bb.mp4
84+
85+
Video Pathlink: https://github.com/DurgaSai-16/Awesome_Python_Scripts/blob/main/AutomationScripts/Wiki%20Bot/Media/Videos/Wiki_Bot_Output_2.mp4
86+
87+
## Author:
88+
[NALLANI DURGA SAI](https://github.com/DurgaSai-16)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import pyttsx3 as py #Text to speech Library
2+
import datetime #Date & Time Library
3+
import speech_recognition as sr #Speech recognition
4+
import wikipedia #Wikipedia Library
5+
import urllib.request #URL Library
6+
import os #Operating System Library
7+
import pyaudio #Audio Library
8+
------------ #Intialization -----------
9+
engine = py.init('sapi5')
10+
engine.setProperty('rate', 150)
11+
voices = engine.getProperty('voices')
12+
engine.setProperty('voices',voices[0].id)
13+
14+
def speak(audio): #Audio Output
15+
engine.say(audio)
16+
engine.runAndWait()
17+
18+
def wishme(): #Greetings
19+
hour =int(datetime.datetime.now().hour)
20+
if(hour>=0 and hour<12):
21+
speak("Good Morning!, Durga Sai ")
22+
elif(hour>=12 and hour<18):
23+
speak("Good Afternoon, Durga Sai ")
24+
else:
25+
speak("Good Evening, Durga Sai")
26+
speak("Im wiki bot how may i help you today")
27+
28+
29+
---------------- #Navigation ---------------
30+
def navigate():
31+
r= sr.Recognizer() #Speech
32+
with sr.Microphone() as source:
33+
print("Tell me what you want to search on wikipedia ?")
34+
r.pause_threshold=1
35+
audio = r.listen(source) #To listen (input)
36+
try:
37+
print("Please Wait sir, Search in progress...")
38+
result = r.recognize_google(audio,language='en-in')
39+
print(f"You said:{result}\n") #Confirmation
40+
speak(result) #Output
41+
42+
43+
except Exception as e: #Exceptions
44+
45+
return "None"
46+
return result
47+
def image(query): #Relevant Image from Wiki
48+
query = query.replace(" ","_".lower())
49+
page_image = wikipedia.page(query)
50+
image_down_link = page_image.images[5]
51+
52+
urllib.request.urlretrieve(image_down_link , "loc.jpg")
53+
os.startfile("loc.jpg") #Image display
54+
55+
if __name__ == '__main__':
56+
wishme()
57+
query = navigate().lower()
58+
if "wikipedia " in query:
59+
speak("searching in wiki hang on...!")
60+
query = query.replace("wikipedia ","")
61+
result =wikipedia.summary(query,sentences=2)
62+
image(query)
63+
speak("According to wiki..")
64+
page_image = wikipedia.page(query)
65+
image_down_link = page_image.images[0]
66+
urllib.request.urlretrieve(image_down_link , "loc.jpg")
67+
print(result)
68+
speak(result) #Output
69+
elif '' in query:
70+
try:
71+
72+
speak("searching in wiki hang on...!")
73+
query = query.replace("","")
74+
result =wikipedia.summary(query,sentences=3)
75+
speak("According to wiki..") #Result found
76+
print(result)
77+
image(query)
78+
speak(result)
79+
except Exception as e:
80+
speak("Im sorry i could not found your query") #No result
81+
else:
82+
speak("Im sorry i could not found your query")#No result
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Libraries Imported:
2+
◼️ wikipedia
3+
◼️ datetime
4+
◼️ pyttsx3
5+
◼️ speech recoginition
6+
◼️ pyaudio
7+
◼️ urllib.request
8+
◼️ os

0 commit comments

Comments
 (0)