Welcome to MyAI, a Python-based chatbot powered by Google's Generative AI API. This chatbot is designed to simulate human-like conversations, providing responses to prompts through both text and voice recognition. The project allows users to interact via text input or voice commands and offers text-to-speech responses for a more interactive experience.
- AI-Powered Conversations: Uses Google's Gemini model to generate responses based on user prompts.
- Text and Voice Input: Users can either type commands or speak to the chatbot using voice recognition.
- Text-to-Speech: The chatbot can respond by converting text output into speech.
- Conversation History: Tracks the conversation context to maintain a coherent dialogue.
- Customizable Response Temperature: Adjusts the creativity of the responses by tweaking the temperature setting.
The project contains the following main files:
chatbot.py: Contains theChatBotclass which handles conversation management, prompt processing, and API interactions with Google Generative AI.app.py: The main entry point of the chatbot application that handles user input, text-to-speech (TTS), and speech-to-text (STT) operations.
Before running the project, ensure you have the following dependencies installed:
- Python 3.x
- Required Python packages:
google-generativeaipyttsx3speech_recognitionpython-dotenv
To install these dependencies, you can run:
pip install google-generativeai pyttsx3 speech_recognition python-dotenv-
Clone the repository and navigate to the project directory:
git clone <repository-url> cd myai-chatbot
-
API Key Configuration:
- Obtain your API key from Google Studio
- Create a
.envfile in the project directory and add the following line:GENAI_API_KEY=your_api_key_here
-
Install Packages: Install all the app dependencies with the following command:
pip install -r requirements.txt
-
Run the Application: Start the chatbot by running the following command:
- Terminal
python app.py
- With User Interface
python flask_app.py
-
Usage:
- Type your questions or prompts directly.
- Use the command
clearto clear the conversation history. - Type
exitto quit the chatbot. - Type
voiceto use speech recognition for input instead of typing. - The chatbot will respond in both text and speech.
The chatbot can convert text responses into speech using pyttsx3. This enhances user experience by enabling spoken interaction.
Users can speak their inputs into the microphone, which is then recognized and transcribed into text using the speech_recognition library.
The chatbot uses the GenerativeModel from Google Generative AI to generate responses to user inputs based on the context of the conversation.
-
Conversation Initialization: When you start the chatbot, it loads a pre-defined conversation history or starts fresh if no history is provided.
-
Prompt Submission: You submit prompts to the chatbot either by typing or using voice input. The chatbot sends the prompt to the Generative AI model and receives a response.
-
Response Generation: Based on the prompt, the AI generates a response, which is then displayed to the user and spoken out loud using TTS.
- Add more customizable conversational features.
- Implement advanced NLP-based functionalities to make conversations even more intuitive.
- Enhance the GUI for a better user interface.
- API Key Error: Ensure that your API key is correctly placed in the
.envfile. - Microphone Issues: If speech recognition fails, ensure your microphone is working and configured properly.
- TTS Issues: Check if
pyttsx3is properly installed and configured to use the correct voice settings for your OS.
This project is licensed under the MIT License.
- Google Generative AI for the robust language model.
pyttsx3for text-to-speech capabilities.speech_recognitionfor enabling voice input.
Feel free to contribute or suggest improvements!