diff --git a/kb_workflow/pipeline/processors/srt.py b/kb_workflow/pipeline/processors/srt.py index 436872a..7632e4c 100644 --- a/kb_workflow/pipeline/processors/srt.py +++ b/kb_workflow/pipeline/processors/srt.py @@ -49,7 +49,8 @@ class SRTProcessor(BaseProcessor): self, state_manager: Optional[WorkflowStateManager] = None, enable_correction: bool = True, - enable_semantic_segmentation: bool = False + enable_semantic_segmentation: bool = False, + enable_cache: bool = True ): """初始化 SRT 处理器 @@ -57,6 +58,7 @@ class SRTProcessor(BaseProcessor): state_manager: 状态管理器 enable_correction: 是否启用 ASR 纠错(默认 True) enable_semantic_segmentation: 是否启用 LLM 语义分段(默认 False) + enable_cache: 是否启用缓存(默认 True,仅在启用语义分段时有效) """ super().__init__(state_manager) self.enable_correction = enable_correction @@ -74,10 +76,19 @@ class SRTProcessor(BaseProcessor): # 创建 AI 客户端 ai_client = SimpleAIClient() if ai_client.api_key: - # 创建统一策略,传入 AI 客户端 - strategy = UnifiedSegmentationStrategy(ai_client=ai_client) + # 初始化缓存 + cache = None + if enable_cache: + from kb_workflow.srt.cache import SemanticCache + cache = SemanticCache() + + # 创建统一策略,传入 AI 客户端和缓存 + strategy = UnifiedSegmentationStrategy( + ai_client=ai_client, + cache=cache + ) self.segmenter = SemanticSegmentationEngine(strategy=strategy) - logger.info("Semantic segmentation enabled") + logger.info(f"Semantic segmentation enabled (cache={'enabled' if cache else 'disabled'})") else: logger.info("AI API key not configured, using rule-based segmenter") self.segmenter = SemanticSegmenter()