This project is a Python-based conversational AI chatbot that allows voice-based interactions using speech recognition (for input) and text-to-speech (for output). It uses a pre-trained model (DialoGPT) and can be fine-tuned on custom datasets using training.py.
Check out this demonstration of the Python Voice Interactive Chatbot:
- Project Description
- Features
- Technologies Used
- Installation Instructions
- Usage
- API Documentation
- Testing
- Deployment
- Contributing
- License
- Contact Information
The Voice Interactive Chatbot project is a Python-based conversational AI that allows users to interact with a chatbot via voice commands. Using speech recognition for input and text-to-speech for output, the chatbot can converse with users, answering questions and engaging in dialogue based on a pre-trained model (e.g., DialoGPT). Additionally, the chatbot model can be fine-tuned on custom datasets using training.py for personalized responses.
The project consists of two main components:
- chatbot.py: The core script that runs the voice interaction logic.
- training.py: A script for fine-tuning the chatbot model on custom data to improve its conversational abilities.
This project is available at: https://github.com/jmrashed/voice-interactive-chatbot.git
- Voice Input and Output: Interact with the chatbot using natural voice commands and receive spoken responses.
- Conversational Model: Built using the pre-trained
DialoGPTmodel, fine-tuned for better performance. - Custom Training: Use
training.pyto fine-tune the chatbot on a custom dataset for more relevant responses. - Speech Recognition: Recognizes spoken text using Google Speech Recognition API.
- Text-to-Speech: Responds to users using Python's
pyttsx3library. - Simple Command to Exit: Users can exit the chatbot by saying "exit" or "bye".
- Python 3.x
- SpeechRecognition for speech-to-text conversion.
- pyttsx3 for text-to-speech output.
- transformers from Hugging Face for using and fine-tuning the conversational model (DialoGPT).
- torch for model training and inference.
- datasets from Hugging Face to load conversational datasets.
-
Clone the repository:
git clone https://github.com/jmrashed/voice-interactive-chatbot.git cd voice-interactive-chatbot -
Install the required dependencies:
pip install -r requirements.txt
If you don't have
requirements.txt, you can manually install the dependencies:pip install SpeechRecognition pyttsx3 transformers torch datasets
-
(Optional) Download additional dependencies such as
model weightsif required by your model.
You can configure the voice chatbot in two main ways:
- Model Configuration: Modify the
training.pyfile to use your custom dataset for fine-tuning the model. - Speech Settings: You can change the speech rate, volume, and voice by adjusting the
pyttsx3engine settings inchatbot.py.
-
To run the chatbot with voice interaction:
python chatbot.py
-
To fine-tune the model using a custom dataset:
python training.py
This will train the
DialoGPTmodel on the dataset and save the fine-tuned model in the./resultsdirectory.
- recognize_speech(): Listens for speech input and converts it into text.
- speak(response): Converts text response into speech and outputs it.
- chat(): Main loop for interacting with the chatbot, processing user input, and generating responses.
- load_data(): Loads the dataset for training the model.
- tokenize_data(): Tokenizes the conversational data for the model.
- train_model(): Fine-tunes the pre-trained chatbot model.
Unit tests can be written for individual functions. Example:
- Test the speech-to-text conversion to verify the recognizer works well.
- Test the text-to-speech functionality to ensure the output is correct.
- Ensure that the entire pipeline, from speech input to model output and voice response, works as expected.
- Test different conversational scenarios to ensure the chatbot responds properly.
For deploying the chatbot:
- Local Deployment: The chatbot can be run locally on your machine using Python.
- Web Deployment: You can integrate the chatbot into a web app using a framework like Flask or FastAPI.
- Cloud Deployment: You can deploy it to cloud platforms like AWS, GCP, or Azure using Docker containers.
Please follow the PEP 8 Python coding standards when contributing to the project.
- Fork the repository and create a new branch.
- Make changes in your branch.
- Ensure that your changes don't break existing functionality by testing the system.
- Submit a pull request with a clear description of the changes and why they were made.
This project is licensed under the MIT License - see the LICENSE file for details.
For any inquiries or suggestions, you can reach out to:
- Email: jmrashed@gmail.com
- GitHub: github.com/jmrashed
- Website: rasheduzzaman.com
