An advanced Brain-Computer Interface (BCI) for AI-assisted communication
Project developed for the Hackathon "Fuerza Grupera: Connect your head with AI"
BCI Chat Interface with a chat api is an innovative Augmentative and Alternative Communication (AAC) solution that combines brain-computer interfaces with cutting-edge artificial intelligence. The system enables users with reduced mobility to interact with advanced language models through two complementary modalities:
-
Speller Mode - Letter-by-letter assisted writing
- Native integration with Intendix Speller (Unicorn Hybrid Black)
- Adaptive virtual keyboard with P300 selection
- Context-based intelligent auto-completion
-
Graph Mode - Guided conceptual navigation
- Automatic contextual question generation
- Dynamic decision tree
- Simplified numeric selection (1-9)
The system uses Groq's Llama 3.3 70B model for natural language processing with ultra-low latency (~500ms), optimized for real-time applications. (in this example case)
- Native Intendix Speller support via UDP protocol (port 1000)
- Compatible with Unicorn Hybrid Black EEG device
- Automatic .NET Binary Serialization protocol deserialization
- Advanced character filtering with Unicode validation
- AI Engine: API with Versatile model
- Contextual generation: Up to 9 relevant questions per query
- Real-time streaming: Progressive word-by-word responses
- Conversational history: Context memory for coherent dialogues
- Framework: ttkbootstrap with professional dark theme
- Adaptive design: Responds to user needs
- Clear visualization: Typography optimized for readability
- Status indicators: Real-time visual feedback
- Debug Mode: Complete simulation without BCI hardware
- Error handling: Automatic recovery from failures
- Input validation: Deep Unicode character cleaning
- Smart fallbacks: Alternative responses if API unavailable
- Python: 3.8 or higher
- Operating System: Windows 10/11, Linux, macOS
- Optional Hardware: Unicorn Hybrid Black + Intendix Speller
# 1. Clone the repository
git clone https://github.com/PlekDev/DECUVE.git
cd bci-chat-interface
# 2. Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt| Package | Version | Purpose |
|---|---|---|
ttkbootstrap |
≥1.10.1 | Modern graphical interface |
groq |
≥0.4.0 | Groq API client |
pylsl |
≥1.16.0 | LSL data streaming (optional) |
# Manual dependency installation
pip install ttkbootstrap>=1.10.1
pip install groq>=0.4.0
pip install pylsl>=1.16.0 # Optional for LSLGet your free Groq API key:
- Visit console.groq.com/keys
- Create an account or sign in
- Generate a new API key
Option 1 - Graphical interface (recommended):
- Run the application
- Click "Configure API Key"
- Paste your key and save
Option 2 - Source code:
# In main.py, line 24
GROQ_API_KEY = "your-api-key-here"# Run the application
python main.py-
Start the system
- Click "Start Interface"
- System will begin listening on UDP port 1000
- Confirmation message appears in chat
-
Write query
- Use Intendix Speller to write your question
- Each character appears in real-time
- End with
!to generate questions
-
Select question
- System generates 6-9 numbered questions
- Visual menu appears in chat
- Use Speller to type the number (1-9)
-
Receive response
- Question automatically sent to Groq
- Streaming response appears word by word
- Continue cycle for new queries
-
Switch to Graph mode
- Select "Graph (suggestions)" radio button
-
Enter keywords
- Type concepts separated by commas
- Example:
AI, health, ethics
-
Generate questions
- Click "Generate Questions"
- Wait 2-3 seconds
-
Select and send
- Click on a question to select it
- Click "✉ Send this question to Chat"
- Read complete response
Perfect for development without BCI hardware:
# Debug mode is enabled by default
debug_mode = True # Line 59 in main.pyDebug mode features:
- Automatic click simulation every 1.2s
- Random EEG data
- No physical hardware required
- Ideal for testing and development
┌─────────────────────────────────────────────────────────┐
│ GUI Layer (Tkinter) │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Speller │ │ Graph │ │ Chat Display│ │
│ │ Interface │ │ Navigator │ │ │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└───────────────────────┬─────────────────────────────────┘
│
┌───────────────────────▼─────────────────────────────────┐
│ Processing Layer (Threading) │
│ ┌──────────────────────────────────────────────────┐ │
│ │ UDP Listener → Queue Manager → Processor │ │
│ └──────────────────────────────────────────────────┘ │
└───────────────────────┬─────────────────────────────────┘
│
┌───────────────────────▼─────────────────────────────────┐
│ Integration Layer │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Intendix UDP │ │ Groq API │ │
│ │ (Port 1000) │ │ (Llama 3.3 70B) │ │
│ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────┘
UDP Packet Format:
Maximum size: 12264 bytes
Format: .NET Binary Serialization
Encoding: UTF-8
Port: 1000 (localhost)
Deserialization Process:
- Search for
0x06marker (.NET string start) - Read ULEB128 length (variable-length encoding)
- Extract UTF-8 bytes
- Validate and clean character (
clean_characterfunction)
# Allowed characters whitelist
allowed = set('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'abcdefghijklmnopqrstuvwxyz'
'0123456789 .,;:?!¿¡áéíóúÁÉÍÓÚñÑüÜ')
# Cleaning process:
# 1. Remove Unicode control characters (category C)
# 2. Verify whitelist
# 3. Take only first character if multiple# Question generation (fast)
model="llama-3.3-70b-versatile"
temperature=0.6
max_tokens=200
stream=False
# Conversational responses (streaming)
model="llama-3.3-70b-versatile"
temperature=0.7
max_tokens=500
stream=True# Main states
conversation_history = [] # Chat history with AI
decision_tree = {} # Question tree
current_question_map = {} # Number → question mapping
waiting_for_selection = False # Selection mode flag
buffered_text = "" # Temporary writing bufferUser profile: People with ALS, cerebral palsy, or spinal cord injuries
Benefits:
- Faster communication than traditional spelling (40% less time)
- Expression of complex ideas through predefined questions
- Reduced cognitive fatigue with guided navigation
Applications:
- Development of optimized P300 protocols
- Testing of adaptive interfaces
- Validation of classification algorithms
Measurable metrics:
- Selection accuracy
- Response time
- Character Error Rate (CER)
Functionality:
- Generation of conceptual trees
- Guided exploration of complex topics
- AI-assisted interactive learning
# In main.py, line 56
alphabet = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 _.,?!")
# Example: Extended Spanish alphabet
alphabet = list("ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ0123456789 _.,?!¿¡")# In main.py, run_interface() function (line ~600)
time.sleep(1.2) # Change to simulate different speed# In main.py, generate_initial_questions_thread() function (line ~490)
suggestions = suggestions[:9] # Change limit (1-9 recommended)# To send markers to external analysis systems
info = StreamInfo('BCIInterface', 'Markers', 1, 0, 'string', 'bci_marker')
outlet = StreamOutlet(info)
outlet.push_sample([selected_character])| Metric | Typical Value | Conditions |
|---|---|---|
| Groq API Latency | 300-800ms | Question generation |
| Streaming latency | 50-150ms/token | Conversational responses |
| UDP Processing | <10ms | Packet deserialization |
| GUI Update | 50ms | Queue polling cycle |
| Character accuracy | >95% | With calibrated Intendix |
Solution:
- Verify your API key has more than 10 characters
- Use "Configure API Key" button in interface
- Restart application after configuration
Solution:
pip install groq --upgrade
# Or specify version:
pip install groq==0.4.2Diagnosis:
- Verify Intendix is configured for UDP port 1000
- Check Windows firewall (allow local UDP traffic)
- Review console logs: "Waiting for data from Intendix Speller..."
Solution:
# Verify correct port in main.py, line 153
sock.bind(("127.0.0.1", 1000))Known issue: Some UDP packets contain control characters
Implemented solution:
- Automatic cleaning with
clean_character() - Allowed characters whitelist
- Rejection of Unicode control categories
Solution:
- Groq offers generous free tier (typically 30 req/min)
- Wait 60 seconds between intensive queries
- Consider upgrading to paid plan for higher throughput
- Multi-language support: Complete i18n system
- Real P300 algorithm: ML classifier implementation
- Conversation persistence: Save/load history
- Usage metrics: Analytics dashboard
- Synthesized voice: Text-to-speech for responses
- Offline mode: Local model with llama.cpp
- PEP 8 for Python style
- Type hints for public functions
- Docstrings for classes and complex functions
- Unit tests for critical functionality
This project is licensed under the code name unicorn speller hybrid black. https://github.com/unicorn-bi/Unicorn-Speller-Hybrid-Black/blob/main/UnicornSpeller.md
These are the GitHub profiles of the team members who contributed to this project:
- Groq for providing free access to their ultra-fast API
- Unicorn (g.tec) for research-grade EEG hardware
- Intendix for the established BCI communication system
- Python BCI community for resources and support
⭐ If you find this project useful, consider giving it a star on GitHub ⭐
Made with ❤️ for the BCI community