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
index.htmlvoice_recognition.js
templates/index.html
Raw Download
Find: Go to:
<!DOCTYPE html>
<html lang="en">
<head>
    <!--
    Fitness Coach Bot - Main Interface
    Author: RSK World (https://rskworld.in)
    Founded by: Molla Samser
    Designer & Tester: Rima Khatun
    Contact: help@rskworld.in, +91 93305 39277
    Year: 2026
    -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Fitness Coach Bot - Your Personal AI Fitness Trainer</title>
    <meta name="description" content="AI-powered fitness coaching chatbot for workout plans, exercise guidance, and health tracking">
    <meta name="keywords" content="fitness coach, workout plans, exercise guidance, health tracking, AI chatbot">
    <meta name="author" content="RSK World">
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/advanced-features.css') }}" rel="stylesheet">
</head>
<body class="bg-light">
    <!-- Header -->
    <header class="bg-primary text-white py-3 shadow">
        <div class="container">
            <div class="row align-items-center">
                <div class="col-md-8">
                    <h1 class="h3 mb-0">
                        <i class="fas fa-dumbbell me-2"></i>
                        Fitness Coach Bot
                    </h1>
                    <p class="mb-0 small">Your Personal AI Fitness Trainer</p>
                </div>
                <div class="col-md-4 text-md-end">
                    <span class="badge bg-success me-2">Online</span>
                    <small>Powered by RSK World</small>
                </div>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="container my-4">
        <div class="row">
            <!-- Chat Section -->
            <div class="col-lg-8 mb-4">
                <div class="card shadow-sm h-100">
                    <div class="card-header bg-white">
                        <h5 class="mb-0">
                            <i class="fas fa-comments me-2 text-primary"></i>
                            Chat with Your Fitness Coach
                        </h5>
                    </div>
                    <div class="card-body p-0">
                        <!-- Chat Messages -->
                        <div id="chatMessages" class="chat-messages p-3" style="height: 400px; overflow-y: auto;">
                            <div class="message bot-message mb-3">
                                <div class="d-flex">
                                    <div class="bot-avatar me-2">
                                        <i class="fas fa-robot text-primary"></i>
                                    </div>
                                    <div class="message-content bg-light rounded p-3">
                                        <p class="mb-0">Hello! I'm your fitness coach bot. I'm here to help you with workout plans, exercise guidance, and health tracking. What would you like to know today?</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Chat Input -->
                        <div class="chat-input p-3 border-top">
                            <div class="input-group">
                                <input type="text" id="messageInput" class="form-control" placeholder="Ask about workouts, nutrition, or fitness goals..." maxlength="500">
                                <button class="btn btn-primary" type="button" id="sendButton">
                                    <i class="fas fa-paper-plane"></i> Send
                                </button>
                            </div>
                            <div class="mt-2">
                                <small class="text-muted">Quick suggestions:</small>
                                <div class="mt-1">
                                    <button class="btn btn-sm btn-outline-secondary me-1 mb-1 quick-suggestion">Create workout plan</button>
                                    <button class="btn btn-sm btn-outline-secondary me-1 mb-1 quick-suggestion">Nutrition advice</button>
                                    <button class="btn btn-sm btn-outline-secondary me-1 mb-1 quick-suggestion">Track progress</button>
                                    <button class="btn btn-sm btn-outline-secondary me-1 mb-1 quick-suggestion">Motivation</button>
                                </div>
                                <div class="mt-2">
                                    <button class="btn btn-sm btn-outline-info" id="voiceToggleButton" title="Voice Commands">
                                        <i class="fas fa-microphone"></i> Voice Command
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Sidebar -->
            <div class="col-lg-4">
                <!-- User Profile -->
                <div class="card shadow-sm mb-4">
                    <div class="card-header bg-white">
                        <h6 class="mb-0">
                            <i class="fas fa-user me-2 text-primary"></i>
                            Your Profile
                        </h6>
                    </div>
                    <div class="card-body">
                        <form id="profileForm">
                            <div class="mb-3">
                                <label for="userName" class="form-label">Name</label>
                                <input type="text" class="form-control form-control-sm" id="userName" placeholder="Your name">
                            </div>
                            <div class="row">
                                <div class="col-6 mb-3">
                                    <label for="userAge" class="form-label">Age</label>
                                    <input type="number" class="form-control form-control-sm" id="userAge" placeholder="25">
                                </div>
                                <div class="col-6 mb-3">
                                    <label for="userWeight" class="form-label">Weight (kg)</label>
                                    <input type="number" class="form-control form-control-sm" id="userWeight" placeholder="70">
                                </div>
                            </div>
                            <div class="mb-3">
                                <label for="userGoal" class="form-label">Fitness Goal</label>
                                <select class="form-select form-select-sm" id="userGoal">
                                    <option value="">Select goal...</option>
                                    <option value="weight_loss">Weight Loss</option>
                                    <option value="muscle_gain">Muscle Gain</option>
                                    <option value="endurance">Endurance</option>
                                    <option value="strength">Strength</option>
                                    <option value="general_fitness">General Fitness</option>
                                </select>
                            </div>
                            <button type="submit" class="btn btn-primary btn-sm w-100">Save Profile</button>
                        </form>
                    </div>
                </div>

                <!-- Quick Stats -->
                <div class="card shadow-sm mb-4">
                    <div class="card-header bg-white">
                        <h6 class="mb-0">
                            <i class="fas fa-chart-line me-2 text-primary"></i>
                            Quick Stats
                        </h6>
                    </div>
                    <div class="card-body">
                        <div class="row text-center">
                            <div class="col-6 mb-3">
                                <div class="stat-item">
                                    <h4 class="text-primary mb-0" id="workoutCount">0</h4>
                                    <small class="text-muted">Workouts</small>
                                </div>
                            </div>
                            <div class="col-6 mb-3">
                                <div class="stat-item">
                                    <h4 class="text-success mb-0" id="streakCount">0</h4>
                                    <small class="text-muted">Day Streak</small>
                                </div>
                            </div>
                            <div class="col-6">
                                <div class="stat-item">
                                    <h4 class="text-info mb-0" id="caloriesCount">0</h4>
                                    <small class="text-muted">Calories</small>
                                </div>
                            </div>
                            <div class="col-6">
                                <div class="stat-item">
                                    <h4 class="text-warning mb-0" id="goalsCount">0</h4>
                                    <small class="text-muted">Goals Met</small>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Health Tips -->
                <div class="card shadow-sm">
                    <div class="card-header bg-white">
                        <h6 class="mb-0">
                            <i class="fas fa-lightbulb me-2 text-warning"></i>
                            Health Tips
                        </h6>
                    </div>
                    <div class="card-body">
                        <div id="healthTips">
                            <div class="tip-item mb-2">
                                <small class="text-muted">💡 Drink at least 8 glasses of water daily</small>
                            </div>
                            <div class="tip-item mb-2">
                                <small class="text-muted">🥗 Include protein in every meal</small>
                            </div>
                            <div class="tip-item">
                                <small class="text-muted">😴 Get 7-9 hours of quality sleep</small>
                            </div>
                        </div>
                        <button class="btn btn-sm btn-outline-primary mt-2" id="refreshTips">
                            <i class="fas fa-sync-alt"></i> More Tips
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Features Section -->
        <div class="row mt-4">
            <div class="col-12">
                <div class="card shadow-sm">
                    <div class="card-header bg-white">
                        <h5 class="mb-0">
                            <i class="fas fa-star me-2 text-warning"></i>
                            Features
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-3 mb-3">
                                <div class="feature-card text-center p-3">
                                    <i class="fas fa-clipboard-list fa-2x text-primary mb-2"></i>
                                    <h6>Workout Plans</h6>
                                    <small class="text-muted">Personalized workout routines</small>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="feature-card text-center p-3">
                                    <i class="fas fa-running fa-2x text-success mb-2"></i>
                                    <h6>Exercise Guidance</h6>
                                    <small class="text-muted">Proper form and technique</small>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="feature-card text-center p-3">
                                    <i class="fas fa-chart-bar fa-2x text-info mb-2"></i>
                                    <h6>Progress Tracking</h6>
                                    <small class="text-muted">Monitor your improvements</small>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="feature-card text-center p-3">
                                    <i class="fas fa-heart fa-2x text-danger mb-2"></i>
                                    <h6>Health Tips</h6>
                                    <small class="text-muted">Nutrition and wellness advice</small>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Voice Recognition Indicator -->
        <div id="voiceListeningIndicator" class="voice-listening-indicator position-fixed" style="display: none; bottom: 100px; right: 30px; background: rgba(0,0,0,0.8); color: white; padding: 15px 20px; border-radius: 20px; z-index: 999;">
            <div class="d-flex align-items-center">
                <div class="spinner-border spinner-border-sm text-primary me-2" role="status"></div>
                <span>Listening...</span>
            </div>
        </div>

        <!-- Pose Detection Container -->
        <div id="poseDetectionContainer" class="mt-4" style="display: none;">
            <div class="card shadow-sm">
                <div class="card-header bg-white">
                    <h5 class="mb-0">
                        <i class="fas fa-video me-2 text-primary"></i>
                        Pose Detection & Form Correction
                    </h5>
                </div>
                <div class="card-body">
                    <div id="poseFeedback" class="alert alert-info mb-3"></div>
                    <div class="row">
                        <div class="col-md-8">
                            <div id="poseCanvasContainer" class="pose-detection-container"></div>
                        </div>
                        <div class="col-md-4">
                            <div class="pose-stats p-3">
                                <h6 class="mb-3">Live Stats</h6>
                                <div class="rep-counter mb-3">
                                    <div class="mb-2">Reps: <span id="repCounter" class="text-primary fw-bold">0</span></div>
                                    <div class="form-score mb-2">Form Score: <span id="formScore" class="text-warning fw-bold">0%</span></div>
                                    <div>Exercise: <span id="currentExercise" class="text-info">None</span></div>
                                </div>
                                <button class="btn btn-danger w-100" onclick="if(window.poseDetector) window.poseDetector.stopDetection()">
                                    <i class="fas fa-stop"></i> Stop Detection
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <!-- Footer -->
    <footer class="bg-dark text-white py-4 mt-5">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <h6>Fitness Coach Bot</h6>
                    <p class="small mb-0">Your AI-powered personal fitness trainer for workout plans, exercise guidance, and health tracking.</p>
                </div>
                <div class="col-md-6 text-md-end">
                    <p class="small mb-0">
                        © 2026 RSK World. All rights reserved.<br>
                        Developed by: Molla Samser | Designed & Tested by: Rima Khatun<br>
                        Contact: <a href="mailto:help@rskworld.in" class="text-white">help@rskworld.in</a> | +91 93305 39277
                    </p>
                </div>
            </div>
        </div>
    </footer>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <!-- Chart.js for Analytics -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
    <!-- Custom JS -->
    <script src="{{ url_for('static', filename='js/app.js') }}"></script>
    <script src="{{ url_for('static', filename='js/voice_recognition.js') }}"></script>
    <script src="{{ url_for('static', filename='js/pose_detection.js') }}"></script>
    <script src="{{ url_for('static', filename='js/analytics_dashboard.js') }}"></script>
</body>
</html>
327 lines•17.3 KB
markup
static/js/voice_recognition.js
Raw Download
Find: Go to:
/**
 * Voice Recognition for Hands-Free Workouts
 * Author: RSK World (https://rskworld.in)
 * Founded by: Molla Samser
 * Designer & Tester: Rima Khatun
 * Contact: help@rskworld.in, +91 93305 39277
 * Year: 2026
 */

class VoiceRecognition {
    constructor() {
        this.recognition = null;
        this.isListening = false;
        this.onResultCallback = null;
        this.init();
    }

    init() {
        // Check for browser support
        const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
        
        if (!SpeechRecognition) {
            console.warn('Speech recognition not supported in this browser');
            this.showUnsupportedMessage();
            return;
        }

        this.recognition = new SpeechRecognition();
        this.recognition.continuous = false;
        this.recognition.interimResults = false;
        this.recognition.lang = 'en-US';

        this.recognition.onresult = (event) => {
            const transcript = event.results[0][0].transcript;
            if (this.onResultCallback) {
                this.onResultCallback(transcript);
            }
        };

        this.recognition.onerror = (event) => {
            console.error('Speech recognition error:', event.error);
            this.handleError(event.error);
        };

        this.recognition.onend = () => {
            this.isListening = false;
            this.updateUI();
        };
    }

    startListening(callback) {
        if (!this.recognition) {
            alert('Voice recognition not supported in your browser');
            return;
        }

        if (this.isListening) {
            this.stopListening();
            return;
        }

        this.onResultCallback = callback;
        this.isListening = true;
        
        try {
            this.recognition.start();
            this.updateUI();
            this.showListeningIndicator();
        } catch (error) {
            console.error('Error starting recognition:', error);
        }
    }

    stopListening() {
        if (this.recognition && this.isListening) {
            this.recognition.stop();
            this.isListening = false;
            this.updateUI();
            this.hideListeningIndicator();
        }
    }

    updateUI() {
        const button = document.getElementById('voiceToggleButton');
        if (button) {
            if (this.isListening) {
                button.innerHTML = '<i class="fas fa-microphone-slash"></i> Stop Listening';
                button.classList.add('btn-danger');
                button.classList.remove('btn-primary');
            } else {
                button.innerHTML = '<i class="fas fa-microphone"></i> Voice Command';
                button.classList.add('btn-primary');
                button.classList.remove('btn-danger');
            }
        }
    }

    showListeningIndicator() {
        let indicator = document.getElementById('voiceListeningIndicator');
        if (!indicator) {
            indicator = document.createElement('div');
            indicator.id = 'voiceListeningIndicator';
            indicator.className = 'voice-listening-indicator';
            indicator.innerHTML = `
                <div class="listening-pulse"></div>
                <p>Listening...</p>
            `;
            document.body.appendChild(indicator);
        }
        indicator.style.display = 'block';
    }

    hideListeningIndicator() {
        const indicator = document.getElementById('voiceListeningIndicator');
        if (indicator) {
            indicator.style.display = 'none';
        }
    }

    handleError(error) {
        let message = 'Voice recognition error occurred';
        
        switch (error) {
            case 'no-speech':
                message = 'No speech detected. Please try again.';
                break;
            case 'audio-capture':
                message = 'No microphone found. Please connect a microphone.';
                break;
            case 'not-allowed':
                message = 'Microphone permission denied. Please allow microphone access.';
                break;
            case 'network':
                message = 'Network error. Please check your connection.';
                break;
        }

        this.showError(message);
        this.stopListening();
    }

    showError(message) {
        const errorDiv = document.createElement('div');
        errorDiv.className = 'alert alert-warning alert-dismissible fade show position-fixed';
        errorDiv.style.cssText = 'top: 20px; right: 20px; z-index: 9999; min-width: 300px;';
        errorDiv.innerHTML = `
            ${message}
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        `;
        document.body.appendChild(errorDiv);

        setTimeout(() => {
            errorDiv.remove();
        }, 5000);
    }

    showUnsupportedMessage() {
        const message = document.createElement('div');
        message.className = 'alert alert-info';
        message.innerHTML = `
            <strong>Voice recognition not available</strong><br>
            Your browser doesn't support voice recognition. Please use Chrome, Edge, or Safari.
        `;
        const voiceSection = document.getElementById('voiceSection');
        if (voiceSection) {
            voiceSection.appendChild(message);
        }
    }

    speak(text) {
        if ('speechSynthesis' in window) {
            const utterance = new SpeechSynthesisUtterance(text);
            utterance.lang = 'en-US';
            utterance.rate = 1.0;
            utterance.pitch = 1.0;
            
            // Use a more natural voice if available
            const voices = speechSynthesis.getVoices();
            const preferredVoice = voices.find(voice => 
                voice.lang.includes('en') && voice.name.includes('Natural')
            ) || voices.find(voice => voice.lang.includes('en-US'));
            
            if (preferredVoice) {
                utterance.voice = preferredVoice;
            }
            
            speechSynthesis.speak(utterance);
        }
    }
}

// Initialize voice recognition
document.addEventListener('DOMContentLoaded', () => {
    window.voiceRecognition = new VoiceRecognition();

    // Setup voice toggle button
    const voiceButton = document.getElementById('voiceToggleButton');
    if (voiceButton) {
        voiceButton.addEventListener('click', () => {
            if (window.voiceRecognition.isListening) {
                window.voiceRecognition.stopListening();
            } else {
                window.voiceRecognition.startListening(async (transcript) => {
                    console.log('Voice command:', transcript);
                    
                    // Send to backend
                    try {
                        const response = await fetch('/api/voice/command', {
                            method: 'POST',
                            headers: {
                                'Content-Type': 'application/json',
                            },
                            body: JSON.stringify({ transcript: transcript })
                        });
                        
                        const data = await response.json();
                        
                        if (data.success && data.response) {
                            // Display response
                            if (window.fitnessBot) {
                                window.fitnessBot.addMessage(data.response, 'bot');
                            }
                            
                            // Speak response
                            window.voiceRecognition.speak(data.response);
                        }
                    } catch (error) {
                        console.error('Error processing voice command:', error);
                    }
                });
            }
        });
    }
});
235 lines•8 KB
javascript

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