A voice-first AI-powered mental performance coach for athletes, built with Streamlit, CrewAI, Ollama, and voice technologies. The app allows athletes to create profiles, engage in interactive voice-based consultations, receive personalized coaching recommendations, and get daily audio reminders. It focuses on mental aspects like confidence, stress management, focus, and motivation.
- Interactive Voice Consultation: Natural conversation with Coach Alex using speech recognition and TTS.
- Personalized Coaching: Generates tailored mental performance strategies based on athlete profile and responses.
- Data Collection: Collects athlete details (age, sport, goals) through conversational flow.
- Assessment Questions: Asks and processes responses to personalized questions.
- Coaching Analysis: Provides comprehensive analysis with key insights and action plans.
- Audio Output: Uses ElevenLabs TTS for high-quality voice (fallback to gTTS or pyttsx3).
- Speech Recognition: Supports voice input using microphone.
- Database Persistence: Saves athlete profiles and consultation logs in SQLite.
- Daily Reminders: Generates and plays audio reminders with coaching tips.
- Streamlit UI: User-friendly interface for profile setup, assessment, and coaching.
- Pygame Audio Playback: Handles audio playback for a seamless experience.
- Hardware:
- Microphone for voice input.
- Speakers/headphones for audio output.
- Quiet environment for speech recognition.
- Software:
- Python 3.10 or higher (tested on 3.11).
- Ollama with a model (e.g.,
llama3.2:latestorphi-2for lower memory usage). - Internet connection for ElevenLabs TTS (optional; fallback to offline TTS).
- API Keys:
- ElevenLabs API key (for high-quality TTS; get from ElevenLabs).
- System Memory:
- At least 4 GB RAM (for
llama3.2:latest) or 2 GB (forphi-2).
- At least 4 GB RAM (for
-
Clone the Repository (if applicable):
git clone <repository_url> cd voice.py -
Set Up Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate -
Install Dependencies:
pip install streamlit crewai langchain-ollama pyttsx3 speechrecognition gtts pygame requests -
Install Ollama:
- Download and install Ollama from https://ollama.com/download.
- Pull and run the model:
ollama pull llama3.2:latest # Or phi-2 for lower memory ollama serve - Ensure it's running at
http://localhost:11434.
-
Set ElevenLabs API Key:
- Add to your environment:
export ELEVENLABS_API_KEY="your_elevenlabs_api_key_here" - Or update the script's
ELEVENLABS_API_KEYvariable.
- Add to your environment:
-
Set Up Audio Dependencies:
- On Windows, install Microsoft Visual C++ Build Tools for
pyaudio(part ofspeechrecognition): Download here.
- On Windows, install Microsoft Visual C++ Build Tools for
-
Run the App:
streamlit run voice.py- Open your browser to
http://localhost:8501.
- Open your browser to
-
Interact with the App:
- Profile Setup: Enter your name, age, weight, height, sport type, experience level, training frequency, and goals.
- Welcome Phase: Listen to Coach Alex's welcome audio and respond.
- Assessment Phase: Answer 6 personalized questions via voice or text.
- Coaching Phase: Receive personalized coaching analysis, recommendations with confidence scores (e.g., "90%", "85%"), and action plans.
- Audio and JSON: Play/download audio, view JSON output with recommendations and confidence scores.
- Daily Reminders: Generate and download daily audio reminders.
- Save Session: Save your profile and session data to SQLite.
-
Example JSON Output (includes confidence scores):
{ "session_id": "<uuid>", "athlete_name": "<name>", "sport_type": "<sport>", "athlete_level": "<level>", "training_frequency": <number>, "goals": ["<goal1>", "<goal2>"], "responses": { "question_1": "<response>", ... }, "recommendations": [ { "recommendation": "<recommendation>", "justification": "<justification>", "confidence_score": "90%" }, ... ] } -
Audio Playback:
- Uses pygame for automatic playback.
- Audio includes recommendations with confidence scores (e.g., "Practice deep breathing... with 90% confidence").
- Ollama Model: Change
Config.MODEL_NAMEto a different model (e.g.,llama3.2:latestfor higher accuracy, but requires more RAM). - API Base: Update
Config.API_BASEif Ollama runs on a different port. - ElevenLabs Voice ID: Change
ELEVENLABS_VOICE_IDfor a different voice (e.g., "pNInz6obpgDQGcFmaJgB" for Adam). - Database Path: Change
DATABASE_PATHif you want a different SQLite file location. - Max Response Length: Adjust
MAX_RESPONSE_LENGTHfor TTS response length.
- **StreamlitAPIException (Duplicate Forms