Skip to content
23 changes: 17 additions & 6 deletions chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
import speech_recognition as sr
from google_places import *
import pyjokes
import string
from spellchecker import SpellChecker
# from speech_recognition.__main__ import r, audio

# to remove punctuations from input string
table = str.maketrans('', '', string.punctuation)
# to check spelling errors
spell = SpellChecker()

engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[10].id)
Expand All @@ -20,9 +27,9 @@

engine.setProperty('rate', rate - 25)

greetings = ['hey there', 'hello', 'hi', 'Hai', 'hey!', 'hey', 'hi there!']
question = ['How are you?', 'How are you doing?', 'What\'s up?']
responses = ['Okay', "I'm fine"]
greetings = ['hey there', 'hello', 'hi', 'hai', 'hey', 'hi there']
question = ['how are you', 'how are you doing', "whats up"]
responses = ['Okay', "I'm fine", "I am fine."]
var1 = ['who made you', 'who created you']
var2 = ['I_was_created_by_Edward_right_in_his_computer.',
'Edward', 'Some_guy_whom_i_never_got_to_know.']
Expand All @@ -41,8 +48,7 @@
cmd7 = [
'what is your color',
'what is your colour',
'your color',
'your color?']
'your color']
colrep = [
'Right now its rainbow',
'Right now its transparent',
Expand All @@ -61,7 +67,10 @@
while True:
speech_type = input('Speech/Text: ')
if speech_type.lower() != "speech":
translate = input("Type: ")
translate = input("Type: ").lower()
translate = translate.translate(table)
translate = spell.correction(translate)
# print(translate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the usecase of comment statement. can it notify user when wrong spell.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gargi, Any update on this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented statement was to check if the pyspellchecker object accurately corrects the misspelled words. Yes, we can uncomment it and show the user the corrected statement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, can you remove this or put a comment regarding explaining how it works. #print looks like a debug statement.

else:
now = datetime.datetime.now()
r = sr.Recognizer()
Expand All @@ -73,7 +82,9 @@
audio = r.listen(source)
try:
translate = r.recognize_google(audio)
translate = spell.correction(translate)
print("You said:- " + translate)
translate = translate.translate(table)
except sr.UnknownValueError:
print("Could not understand audio")
engine.say('I didnt get that. Rerun the code')
Expand Down