Voice-based AI chatbot powered by OpenAI
Project description
Chatbot
This project is a voice-based chatbot that uses OpenAI's API to interact with users. The chatbot listens to user input via voice, processes the input using OpenAI's whisper model for transcription, generates a response using the GPT-3.5-turbo model, and replies using text-to-speech model tts-1.
Features
- Voice Input: Users interact with the chatbot using their voice.
- Real-Time Transcription: Converts voice input into text using OpenAI's
whispermodel. - Intelligent Responses: Generates context-aware and empathetic responses using OpenAI's
GPT-3.5-turbomodel. - Voice Output: Uses OpenAI's
tts-1model to respond back in audio form. - Continuous Conversation: Maintains conversation history for context-aware interactions.
- Language support:
whispercan detect any language. Your accent can affect language detection!
Prerequisites
- Python 3.9+
- uv — a modern Python package manager
- OpenAI API Key
- Virtual environment (optional but recommended)
- A working microphone and speaker
Installation
Option 1: Install from PyPI
pip install chatbot-encodedmind
Option 2: Install from source
- Clone the repository
git clone https://github.com/EncodedMind/Chatbot.git cd Chatbot
- Create and activate a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Sync dependencies
uv sync - Set your OpenAI API key
Replace
YOUR_OPENAI_API_KEYin the script with your actual OpenAI API key.
Usage
- Run the chatbot If installed via PyPI:
chatbot
or, if installed from source:
uv run chatbot
- Interact with the chatbot
- Speak into your microphone when prompted.
- Listen to the chatbot's response.
- Say "Goodbye" to end the session and exit the program.
Project Structure
├── chatbot/
│ ├── __init__.py
│ ├── ai_client.py # Handles OpenAI API calls
│ ├── audio_io.py # Manages audio input/output
│ └── core.py # Main conversation loop
├── pyproject.toml # Project metadata and dependencies
├── .python-version # Python version for uv
└── README.md # Project documentation
Key Components
Functions
record_audio(duration, fs, device): Captures audio input from the user.get_chatgpt_response(conversation_history): Sends user messages to theGPT-3.5-turbomodel and retrieves responses.main(): Orchestrates the chatbot's voice input/output loop and conversation logic.
Libraries Used
- OpenAI: For GPT and Whisper APIs.
- Sounddevice: For capturing audio input.
- Numpy: For handling audio data.
- Pydub: For playing audio responses.
- Scipy: For saving audio files as
.wav. - Requests: For making HTTP requests to the OpenAI API.
Future Improvements
- Silence Detection: Avoid the limitation of defining a
durationparameter.
Notes
Ensure you have a stable internet connection for API calls. The interaction pause time (or response speed) of the chatbot depends on the quality and speed of your internet connection, as it relies on real-time API calls to OpenAI servers. Modify the chatbot behavior by changing the initial conversation_history system message.
Troubleshooting
Audio Issues: Ensure your microphone is properly configured and accessible to the program.
API Errors: Verify your API key and check for usage limits on your OpenAI account.
Dependency Issues: Ensure all required libraries are installed using uv sync.
Project Extension: Teddy Bear Voice Assistant
In addition to the core functionality of the voice chatbot, I extended the project by integrating it with an Asus Tinker Board. The board acts as the central controller for the chatbot's operations. I connected a microphone and speaker to the Tinker Board and embedded everything inside a teddy bear to create a kid-friendly interactive toy, similar to the Furby.
This project extension aims to provide a fun and engaging experience for children while maintaining the capabilities of the voice chatbot.
Watch the Interaction in Action
You can see the teddy bear in action with the chatbot by watching this video on YouTube:
License
This project is open-source and available under the MIT License.
Acknowledgements
- OpenAI for providing the models.
- The developers of
Sounddevice,PydubandScipyfor enabling audio processing.
Enjoy using the Chatbot!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chatbot_encodedmind-1.0.4.tar.gz.
File metadata
- Download URL: chatbot_encodedmind-1.0.4.tar.gz
- Upload date:
- Size: 54.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
328c0f8380c852328772c40a553b5b43531730c2d9031d0d3d38e8055e5bc442
|
|
| MD5 |
8edc2edb44cec9e15620a40fe8751cd5
|
|
| BLAKE2b-256 |
1fe18694d5cb674bd1a3c34ca2b3f6b5da0c9a485324c0ba0143f78ed5fcdce6
|
File details
Details for the file chatbot_encodedmind-1.0.4-py3-none-any.whl.
File metadata
- Download URL: chatbot_encodedmind-1.0.4-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22871648e6e72117272120ddc502ed0ede06920a508b55fc843d42df74037514
|
|
| MD5 |
09fc89d30f1fc34bc8d573c998b11620
|
|
| BLAKE2b-256 |
558f500b48f891f3488155a359ed1571df0c9d633e0c063f943af295f616c9b1
|