help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
fitness-coach-bot
/
utils
RSK World
fitness-coach-bot
Fitness Coach Bot - Python + Flask + SQLAlchemy + Workout Plans + Exercise Guidance + Health Tracking + AI Fitness Coach
utils
  • __pycache__
  • __init__.py965 B
  • ai_workout_generator.py18 KB
  • analytics_engine.py27.8 KB
  • fitness_coach.py13.3 KB
  • gamification_system.py30.4 KB
  • nutrition_ai.py23.8 KB
  • smart_recovery.py11 KB
  • social_features.py19.4 KB
  • voice_coach.py10 KB
  • wearable_integration.py27 KB
  • workout_buddy_matcher.py9.5 KB
voice_coach.py
utils/voice_coach.py
Raw Download
Find: Go to:
"""
Voice Interaction System for Fitness Coach Bot
Author: RSK World (https://rskworld.in)
Founded by: Molla Samser
Designer & Tester: Rima Khatun
Contact: help@rskworld.in, +91 93305 39277
Year: 2026
"""

import json
import re
from typing import Dict, List, Optional
from datetime import datetime

class VoiceCoach:
    """Advanced voice interaction system for hands-free workout coaching"""
    
    def __init__(self):
        self.commands = self._load_voice_commands()
        self.workout_state = {
            'current_exercise': None,
            'current_set': 0,
            'rep_count': 0,
            'rest_timer': 0,
            'workout_active': False
        }
        self.voice_enabled = False
        
    def _load_voice_commands(self) -> Dict:
        """Load voice command patterns"""
        return {
            'start_workout': [
                r'start.*workout',
                r'begin.*workout',
                r'let.*start',
                r'ready.*go'
            ],
            'next_exercise': [
                r'next.*exercise',
                r'move.*next',
                r'finished.*this',
                r'next.*one'
            ],
            'pause_workout': [
                r'pause.*workout',
                r'stop.*moment',
                r'take.*break',
                r'hold.*on'
            ],
            'resume_workout': [
                r'resume.*workout',
                r'continue',
                r'keep.*going',
                r'start.*again'
            ],
            'rest_timer': [
                r'start.*rest',
                r'rest.*timer',
                r'take.*rest'
            ],
            'rep_count': [
                r'(\d+).*reps?',
                r'did.*(\d+)',
                r'completed.*(\d+)'
            ],
            'form_check': [
                r'check.*form',
                r'how.*looking',
                r'am.*doing'
            ],
            'motivation': [
                r'need.*motivation',
                r'give.*encourage',
                r'cheer.*me',
                r'pump.*up'
            ],
            'finish_workout': [
                r'finish.*workout',
                r'done.*working',
                r'end.*workout',
                r'complete.*workout'
            ]
        }
    
    def process_voice_command(self, transcript: str) -> Dict:
        """Process voice command and return response"""
        transcript_lower = transcript.lower()
        
        # Check for matches
        for command_type, patterns in self.commands.items():
            for pattern in patterns:
                match = re.search(pattern, transcript_lower)
                if match:
                    return self._execute_command(command_type, match, transcript)
        
        # Default response
        return {
            'success': False,
            'response': "I didn't catch that. Could you repeat?",
            'audio_url': None
        }
    
    def _execute_command(self, command_type: str, match: re.Match, transcript: str) -> Dict:
        """Execute voice command"""
        
        if command_type == 'start_workout':
            return self._start_workout()
        elif command_type == 'next_exercise':
            return self._next_exercise()
        elif command_type == 'pause_workout':
            return self._pause_workout()
        elif command_type == 'resume_workout':
            return self._resume_workout()
        elif command_type == 'rest_timer':
            return self._start_rest_timer()
        elif command_type == 'rep_count':
            reps = int(match.group(1)) if match.groups() else 0
            return self._record_reps(reps)
        elif command_type == 'form_check':
            return self._form_check()
        elif command_type == 'motivation':
            return self._motivate()
        elif command_type == 'finish_workout':
            return self._finish_workout()
        
        return {'success': False, 'response': "Command not recognized"}
    
    def _start_workout(self) -> Dict:
        """Start workout voice response"""
        self.workout_state['workout_active'] = True
        responses = [
            "Alright! Let's get started. I'm right here with you. Take a deep breath and let's begin!",
            "Awesome! Time to crush this workout. I'll guide you through every step. Let's go!",
            "Perfect! Let's make this session count. Remember, form over speed. Ready? Let's do this!"
        ]
        return {
            'success': True,
            'response': responses[0],
            'action': 'start_workout',
            'workout_state': self.workout_state
        }
    
    def _next_exercise(self) -> Dict:
        """Move to next exercise"""
        if not self.workout_state['workout_active']:
            return {'success': False, 'response': "No workout active. Say 'start workout' to begin."}
        
        self.workout_state['current_set'] += 1
        responses = [
            f"Great job! Moving to set {self.workout_state['current_set']}. Take a deep breath and let's continue!",
            "Excellent work! Ready for the next one? Let's keep that energy up!",
            "You're doing amazing! Let's move to the next exercise. Stay strong!"
        ]
        return {
            'success': True,
            'response': responses[0],
            'action': 'next_exercise',
            'workout_state': self.workout_state
        }
    
    def _pause_workout(self) -> Dict:
        """Pause workout"""
        self.workout_state['workout_active'] = False
        return {
            'success': True,
            'response': "Workout paused. Take your time. Say 'resume workout' when you're ready to continue.",
            'action': 'pause_workout',
            'workout_state': self.workout_state
        }
    
    def _resume_workout(self) -> Dict:
        """Resume workout"""
        self.workout_state['workout_active'] = True
        return {
            'success': True,
            'response': "Welcome back! Let's pick up where we left off. Ready?",
            'action': 'resume_workout',
            'workout_state': self.workout_state
        }
    
    def _start_rest_timer(self) -> Dict:
        """Start rest timer"""
        return {
            'success': True,
            'response': "Starting 60-second rest timer. Take deep breaths and hydrate. I'll let you know when time's up.",
            'action': 'start_rest_timer',
            'duration': 60
        }
    
    def _record_reps(self, reps: int) -> Dict:
        """Record completed reps"""
        self.workout_state['rep_count'] += reps
        responses = [
            f"Excellent! {reps} reps recorded. Great work!",
            f"Nice! I've logged {reps} reps. Keep pushing!",
            f"Awesome! {reps} reps done. You're on fire!"
        ]
        return {
            'success': True,
            'response': responses[0],
            'action': 'record_reps',
            'reps': reps,
            'total_reps': self.workout_state['rep_count']
        }
    
    def _form_check(self) -> Dict:
        """Provide form feedback"""
        feedback = [
            "Your form looks good! Keep that core tight and maintain control.",
            "Looking strong! Remember to breathe - exhale on exertion, inhale on release.",
            "Great job! Try to slow down a bit and focus on the full range of motion."
        ]
        return {
            'success': True,
            'response': feedback[0],
            'action': 'form_check'
        }
    
    def _motivate(self) -> Dict:
        """Provide motivation"""
        motivational_quotes = [
            "You're stronger than you think! Every rep is progress. Keep going!",
            "Remember why you started! You've got this. Push through!",
            "Your body can do it. It's your mind you need to convince. Let's do this!",
            "No pain, no gain! You're crushing it! Don't stop now!",
            "Every workout makes you stronger. You're becoming unstoppable!"
        ]
        import random
        return {
            'success': True,
            'response': random.choice(motivational_quotes),
            'action': 'motivate'
        }
    
    def _finish_workout(self) -> Dict:
        """Finish workout"""
        self.workout_state['workout_active'] = False
        total_reps = self.workout_state['rep_count']
        
        return {
            'success': True,
            'response': f"Workout complete! Amazing job! You completed {total_reps} total reps. Remember to stretch and hydrate!",
            'action': 'finish_workout',
            'summary': {
                'total_reps': total_reps,
                'total_sets': self.workout_state['current_set'],
                'completed_at': datetime.now().isoformat()
            }
        }
    
    def generate_workout_guidance(self, exercise_name: str, set_number: int) -> Dict:
        """Generate voice guidance for specific exercise"""
        guidance = {
            'squats': f"Alright, set {set_number} of squats. Stand tall, feet shoulder-width apart. Lower down slowly, keep your chest up. Ready? Let's do 12 reps. Go!",
            'pushups': f"Time for set {set_number} of push-ups. Get into plank position, core tight. Lower with control, push back up strong. Let's go for 10 reps!",
            'plank': f"Set {set_number} plank time. Hold that position, straight line from head to heels. Breathe steady. Let's hold for 45 seconds. Starting now!",
            'lunges': f"Set {set_number} lunges coming up. Step forward, lower down, both knees at 90 degrees. Push back to start. 10 reps per leg. Let's do this!"
        }
        
        return {
            'success': True,
            'response': guidance.get(exercise_name.lower(), f"Ready for set {set_number} of {exercise_name}. Let's go!"),
            'exercise': exercise_name,
            'set': set_number
        }
266 lines•10 KB
python

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer