A camera-enabled conversational AI mental health assistant built with Symfony 6, featuring speech-to-text, AI-powered responses, and text-to-speech capabilities.
- Voice Interaction - Speak naturally with the AI coach using microphone input
- AI-Powered Responses - Conversational AI powered by OpenRouter (Claude 3 Haiku)
- Text-to-Speech - AI responses are spoken aloud using OpenAI TTS
- Emotion Analysis - Real-time sentiment analysis detecting mood and stress levels
- Crisis Detection - Automatic detection of crisis keywords with safe, supportive responses
- Modern UI - Clean, intuitive interface with animated AI avatar
- Secure - User authentication, CSRF protection, and rate limiting
┌─────────────────────────────────────────────────────────────┐
│ Browser (Frontend) │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ WebRTC │ │ STT │ │ TTS │ │ UI │ │
│ │ Camera │──│ (audio) │──│ (play) │ │ Panel │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────┘
│ AJAX/Fetch
▼
┌─────────────────────────────────────────────────────────────┐
│ Symfony 6 Backend │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Security │ │ AI │ │ STT │ │ TTS │ │
│ │ (Firewall│──│ Service │──│ Service │──│ Service │ │
│ │ RateLim) │ │(OpenRoute)│ │(Deepgram)│ │(OpenAI) │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Doctrine ORM (MySQL) │ │
│ │ UserSession │ Conversation │ Message │ EmotionAnalysis│
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
| Component | Technology |
|---|---|
| Backend | Symfony 6.4 (PHP 8.1+) |
| Frontend | Twig + Vanilla JavaScript |
| Database | MySQL 8.0 |
| ORM | Doctrine |
| AI (LLM) | OpenRouter (Claude 3 Haiku) |
| Speech-to-Text | Deepgram |
| Text-to-Speech | OpenAI TTS |
| Security | Symfony Security |
- PHP 8.1 or higher
- MySQL 8.0 or higher
- Composer
- Web browser with camera/microphone support
-
Clone the repository
git clone https://github.com/yourusername/chatwell.git cd chatwell -
Install dependencies
composer install
-
Configure environment
Edit
.envfile:DATABASE_URL="mysql://user:password@127.0.0.1:3306/chatwell?serverVersion=8.0.32&charset=utf8mb4"
-
Create database
php bin/console doctrine:database:create php bin/console doctrine:schema:create
-
Create a user
php bin/console app:create-user your@email.com your_password
-
Start the server
php -S localhost:8000 -t public
-
Access the application
Open http://localhost:8000 and login with your credentials.
The application uses the following AI services. Update the service files to use your own keys:
- OpenRouter -
src/Service/OpenRouterService.php - Deepgram -
src/Service/DeepgramService.php - OpenAI TTS -
src/Service/OpenAITtsService.php
chatwell/
├── src/
│ ├── Controller/
│ │ ├── AiAssistantController.php # Main API endpoints
│ │ └── SecurityController.php # Authentication
│ ├── Entity/
│ │ ├── User.php
│ │ ├── UserSession.php
│ │ ├── Conversation.php
│ │ ├── Message.php
│ │ └── EmotionAnalysis.php
│ ├── Service/
│ │ ├── OpenRouterService.php # AI chat
│ │ ├── DeepgramService.php # Speech-to-text
│ │ ├── OpenAITtsService.php # Text-to-speech
│ │ ├── EmotionAnalysisService.php # Sentiment analysis
│ │ └── RateLimiterService.php # Rate limiting
│ └── Command/
│ └── CreateUserCommand.php
├── templates/
│ ├── base.html.twig
│ ├── ai_assistant/
│ │ └── index.html.twig
│ └── security/
│ └── login.html.twig
├── public/
│ ├── js/
│ │ └── ai-assistant.js # WebRTC & AJAX
│ └── css/
│ └── ai-assistant.css
├── config/
│ └── packages/
└── SETUP.md
The AI assistant follows these principles:
- ✅ Provides emotional support and active listening
- ✅ Offers stress management techniques
- ✅ Suggests mindfulness and relaxation exercises
- ✅ Keeps responses under 150 words
- ❌ Never diagnoses medical conditions
- ❌ Never replaces professional mental health care
The AI automatically detects crisis keywords (self-harm, suicide, etc.) and responds with:
- Empathetic acknowledgment
- Crisis hotline information
- Encouragement to seek professional help
- Form-based authentication
- CSRF protection on all forms
- Rate limiting (10 requests/minute per user)
- Input validation
- Password hashing with Symfony password hasher
This project is for educational purposes. Please review and comply with the terms of service for all AI providers used.
- Symfony - PHP framework
- OpenRouter - AI API
- Deepgram - Speech-to-text
- OpenAI - Text-to-speech
Made with ❤️ for mental wellness