""" Machine Learning module for Trixy voice assistant. This module provides comprehensive ML components for client-side AI processing including wakeword detection, voice recognition, audio pipeline management, workflow orchestration, performance monitoring, and application integration. Key Features: - Unified ML coordination for client-side deployment - Complete wakeword -> voice recognition workflow - Real-time audio processing pipeline - Performance monitoring and optimization - Application container integration - Event system integration - Comprehensive error handling Usage: from trixy_core.ml import MLManager, MLConfig, create_client_ml_system # Create complete ML system for client ml_system = create_client_ml_system( application_container=app_container, enable_wakeword=True, enable_voice_recognition=True ) # Start ML processing ml_system.start() """ __version__ = "1.0.0" __author__ = "Trixy Team" # Import core ML components from .wakeword import WakewordDetector, WakewordConfig from .voice_recognition import VoiceRecognitionDetector, VoiceRecognitionConfig # Import unified ML system from .ml_manager import ( MLManager, MLConfig, MLSystemMode as MLMode, MLProcessingState as MLState, create_ml_manager, create_default_ml_config, create_optimized_ml_config, create_debug_ml_config ) # Import audio pipeline from .audio_pipeline import ( AudioPipeline, AudioPipelineConfig, AudioFormat, AudioPipelineState as AudioState, create_audio_pipeline, create_default_audio_config ) # Import new comprehensive modules # from .config import ( # MLConfiguration, ConfigProfile, MLManagerConfig, # create_default_ml_configuration, create_production_ml_configuration, # create_debug_ml_configuration, load_ml_configuration # ) from .event_integration import ( MLEventManager, EventType as MLEventType, EventPriority, ConversationContext as MLEventData, create_ml_event_manager ) from .performance_monitor import ( PerformanceMonitor as MLPerformanceMonitor, MetricType, AlertLevel, PerformanceReport as PerformanceConfig, PerformanceThreshold as PerformanceLevel ) from .container_integration import ( MLContainerManager as MLContainerIntegration ) # from .integration import ( # MLIntegrationConfig, # create_ml_integration # ) # Temporary minimal implementations for basic functionality class MLIntegrationConfig: def __init__(self, **kwargs): self.enable_ml_manager = kwargs.get('enable_ml_manager', True) self.enable_audio_pipeline = kwargs.get('enable_audio_pipeline', True) self.enable_workflow_manager = kwargs.get('enable_workflow_manager', True) self.enable_event_integration = kwargs.get('enable_event_integration', True) self.enable_performance_monitoring = kwargs.get('enable_performance_monitoring', True) self.auto_start_components = kwargs.get('auto_start_components', True) def create_ml_integration(application_container, integration_config): """Temporary minimal ML integration.""" # Get the config from the application container config_manager = application_container.get_config_manager() app_config = config_manager.get_config() event_handler = application_container.get_event_handler() # Convert config.ml (from config_models) to MLConfig (from ml_manager) if hasattr(app_config, 'ml'): ml_section = app_config.ml ml_config = MLConfig( wakeword_model_path=ml_section.wakeword_model_path, wakeword_model_password=getattr(ml_section, 'wakeword_model_password', ''), voice_recognition_model_path=ml_section.voice_recognition_model_path, voice_recognition_model_password=getattr(ml_section, 'voice_recognition_model_password', ''), wakeword_confidence_threshold=ml_section.wakeword_threshold, voice_recognition_confidence_threshold=ml_section.voice_recognition_threshold, enable_optimization=ml_section.enable_gpu, # Map enable_gpu to enable_optimization audio_sample_rate=getattr(app_config, 'audio', None).sample_rate if hasattr(app_config, 'audio') else 16000, audio_channels=getattr(app_config, 'audio', None).channels if hasattr(app_config, 'audio') else 1 ) else: ml_config = create_default_ml_config() # Return the ML manager with the actual config ml_manager = create_ml_manager(ml_config, event_handler, application_container) print(f"DEBUG: create_ml_integration returning type: {type(ml_manager)}, has start: {hasattr(ml_manager, 'start')}") return ml_manager from .error_handling import ( MLErrorHandler, ErrorSeverity, RecoveryStrategy as ErrorHandlingConfig, create_ml_error_handler as create_error_handler ) from .conversation_workflow import ( ConversationWorkflow as MLWorkflowManager, WorkflowConfig, ConversationState as WorkflowState, create_conversation_workflow as create_workflow_manager, create_default_workflow_config ) __all__ = [ # Legacy compatibility "WakewordDetector", "WakewordConfig", "VoiceRecognitionDetector", "VoiceRecognitionConfig", # Core ML Management "MLManager", "MLConfig", "MLMode", "MLState", "create_ml_manager", "create_default_ml_config", # Audio Pipeline "AudioPipeline", "AudioPipelineConfig", "AudioFormat", "AudioState", "create_audio_pipeline", "create_default_audio_config", # Workflow Management "MLWorkflowManager", "WorkflowConfig", "WorkflowState", "create_workflow_manager", "create_default_workflow_config", # Event Integration "MLEventManager", "MLEventType", "MLEventData", "create_ml_event_manager", # Performance Monitoring "MLPerformanceMonitor", "PerformanceConfig", "PerformanceLevel", "create_performance_monitor", # Configuration Management "MLConfigManager", "MLSystemConfig", "PerformanceSettings", "create_ml_config", "create_performance_profile", # Application Integration "MLContainerIntegration", "MLIntegrationConfig", "create_ml_integration", # Error Handling "MLErrorHandler", "ErrorHandlingConfig", "ErrorSeverity", "create_error_handler", # High-level factory functions "create_client_ml_system", "create_standalone_ml_system", ] def create_client_ml_system( application_container, enable_wakeword: bool = True, enable_voice_recognition: bool = True, enable_performance_monitoring: bool = True, **kwargs ) -> MLContainerIntegration: """ Create a complete ML system for client deployment. This is the main factory function for setting up ML processing in client mode with all necessary components. Args: application_container: Trixy application container enable_wakeword: Enable wakeword detection enable_voice_recognition: Enable voice recognition enable_performance_monitoring: Enable performance monitoring **kwargs: Additional configuration options Returns: Configured ML container integration """ # Create integration configuration integration_config = MLIntegrationConfig( enable_ml_manager=True, enable_audio_pipeline=True, enable_workflow_manager=True, enable_event_integration=True, enable_performance_monitoring=enable_performance_monitoring, auto_start_components=True, **kwargs ) # Create ML integration ml_integration = create_ml_integration( application_container=application_container, integration_config=integration_config ) return ml_integration def create_standalone_ml_system( application_container, enable_wakeword: bool = True, enable_voice_recognition: bool = True, enable_continuous_recognition: bool = True, enable_performance_monitoring: bool = True, **kwargs ) -> MLContainerIntegration: """ Create a complete ML system for standalone deployment. Args: application_container: Trixy application container enable_wakeword: Enable wakeword detection enable_voice_recognition: Enable voice recognition enable_continuous_recognition: Enable continuous recognition enable_performance_monitoring: Enable performance monitoring **kwargs: Additional configuration options Returns: Configured ML container integration """ # Create integration configuration for standalone mode integration_config = MLIntegrationConfig( enable_ml_manager=True, enable_audio_pipeline=True, enable_workflow_manager=True, enable_event_integration=True, enable_performance_monitoring=enable_performance_monitoring, auto_start_components=True, **kwargs ) # Create ML integration ml_integration = create_ml_integration( application_container=application_container, integration_config=integration_config ) return ml_integration