Skip to content

sushant247dev/ChatBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

ChatBot

A voice-enabled Python chatbot that fetches info from Wikipedia and replies using text-to-speech. It responds to greetings and keyword-based queries like "what is" or "define". Built with wikipedia and pyttsx3, ideal for beginners exploring chatbots, voice interaction, and basic NLP.

import wikipedia import pyttsx3

engine = pyttsx3.init()

def speak(text): engine.say(text) engine.runAndWait()

keywords = ["what is", "who is", "who are", "what are", "where is", "where are", "when is", "when are", "why is", "why are", "define", "explain", "tell me about", "give me information about"]

while True: user_input = input("You: ").lower()

if "bye" in user_input or "exit" in user_input:
    print("Bot: Bye, Buddy!")
    speak("Bye, Buddy!")
    break

# Greeting and basic replies
elif "hello" in user_input or "hi" in user_input or "hey" in user_input or "what's up?" in user_input:
    print("Bot: Hello there! How can I assist you today?")
    speak("Hello there! How can I assist you today?")

elif "how are you?" in user_input:
    print("Bot: I'm good! How can I assist you today?")
    speak("I'm good! How can I assist you today?")

elif "your name" in user_input:
    print("Bot: I am your friendly assistant, Sushant.bot.")
    speak("I am your friendly assistant, Sushant.bot.")

elif "thank you" in user_input:
    print("Bot: You're welcome! If you have any more questions, feel free to ask.")
    speak("You're welcome! If you have any more questions, feel free to ask.")

# Wikipedia logic
elif any(keyword in user_input for keyword in keywords) or len(user_input.split()) <= 3:
    try:
        for keyword in keywords:
            if keyword in user_input:
                topic = user_input.replace(keyword, "").strip()
                break
        else:
            topic = user_input  # fallback

        summary = wikipedia.summary(topic, sentences=2)
        print("Bot:", summary)
        speak(summary)

    except wikipedia.exceptions.DisambiguationError:
        print("Bot: There are multiple topics related to your query. Please be more specific.")
        speak("There are multiple topics related to your query. Please be more specific.")
    except wikipedia.exceptions.PageError:
        print("Bot: I couldn't find any information on that topic. Please try another query.")
        speak("I couldn't find any information on that topic. Please try another query.")

# Fallback response
else:
    print("Bot: I'm not sure how to respond to that. Try asking about a different topic or say hi.")
    speak("I'm not sure how to respond to that. Try asking about a different topic or say hi.")
    # End of Loopimport wikipedia

About

A voice-enabled Python chatbot that fetches info from Wikipedia and replies using text-to-speech. It responds to greetings and keyword-based queries like "what is" or "define". Built with wikipedia and pyttsx3, ideal for beginners exploring chatbots, voice interaction, and basic NLP.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors