This project presents a simple rule-based chatbot developed in Python designed to interact with users by recognizing specific keywords and phrases. The chatbot provides appropriate predefined responses and converts them into speech using the Google Text-to-Speech (gTTS) library. The system demonstrates basic principles of natural language processing, pattern matching, and audio output generation, offering an introductory framework for building conversational AI applications.
The chatbot was implemented using Python within the Google Colab environment. The process involved the following steps:
Environment Setup: The gTTS library was installed to enable text-to-speech functionality. Other libraries such as datetime and IPython’s display functions were also imported.
Rule Definition: A series of conditional statements (if-elif-else) were used to match user inputs to specific patterns or keywords such as "hello," "time," "joke," etc.
Response Generation: Upon recognizing an input pattern, the chatbot generated an appropriate text response. In the case of time queries, the current system time was fetched using the datetime module.
Text-to-Speech Conversion: Each response was converted to speech using gTTS and saved as an MP3 file. The audio output was then played within the notebook using IPython’s Audio widget.
User Interaction: A while loop enabled continuous interaction with the user until the input "exit" was provided, gracefully terminating the session.
The chatbot successfully responded to a range of user queries, including greetings, inquiries about its identity, time requests, jokes, and conversational prompts. The text responses were accurately converted into speech, providing a dual output mode (text and audio). Sample interactions confirmed that the chatbot could:
Greet users appropriately.
Inform users of the current time.
Tell a joke on request.
Politely handle unrecognized queries with a fallback message.
Convert all responses into clear speech using gTTS.