From 679cca3b2c8e02ef91325dcaa44a57a10d5997e9 Mon Sep 17 00:00:00 2001 From: OpenClaw Agent Date: Tue, 10 Feb 2026 20:34:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(kb-workflow):=20=E4=BC=98=E5=8C=96OCR?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 无论content步骤有没有字幕,都执行ocr步骤 - ocr超时设置为30分钟(1800秒) - 如果没有字幕文件但有视频文件,使用视频作为ocr源 --- skills/kb-workflow/kb_workflow.py | 32 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/skills/kb-workflow/kb_workflow.py b/skills/kb-workflow/kb_workflow.py index b1e9ca4..2ae3b94 100644 --- a/skills/kb-workflow/kb_workflow.py +++ b/skills/kb-workflow/kb_workflow.py @@ -425,19 +425,19 @@ def call_content_agent(platform: str, meta_file: Path, content_dir: Path) -> Dic return call_subagent(agent_id, task, timeout=600) -def call_ocr_processor(subtitle_file: Path, content_dir: Path) -> Dict[str, Any]: +def call_ocr_processor(source_file: Path, content_dir: Path, timeout: int = 1800) -> Dict[str, Any]: """调用 OCR 处理""" - task = f"""处理字幕文件,提取文字内容: + task = f"""处理文件,提取文字内容: -字幕文件: {subtitle_file} +源文件: {source_file} 输出目录: {content_dir} -请读取字幕文件,将内容转换为纯文本。 +请读取文件,提取文字内容。 输出文件名格式: {{platform}}_{{id}}.txt 返回结果时告诉我输出文件的完整路径。""" - return call_subagent(OCR_AGENT, task, timeout=120) + return call_subagent(OCR_AGENT, task, timeout=timeout) def call_deep_analyzer(meta_file: Path, text_file: Path, analyzed_dir: Path) -> Dict[str, Any]: @@ -612,18 +612,26 @@ def process_url(url: str, base_path: Path = None) -> Dict[str, Any]: # OCR text_file = None - if subtitle_file: - print(f"\n{'='*50}") - print(f"步骤5: OCR处理 (kb-ocr-processor)") - print(f"{'='*50}") - - ocr_result = call_ocr_processor(Path(subtitle_file), dirs["content"]) + print(f"\n{'='*50}") + print(f"步骤5: OCR处理 (kb-ocr-processor)") + print(f"{'='*50}") + + # 无论有没有字幕,都尝试OCR处理 + ocr_source = subtitle_file + if not ocr_source and video_file: + ocr_source = video_file + + if ocr_source: + # OCR超时设置为30分钟 + ocr_result = call_ocr_processor(Path(ocr_source), dirs["content"], timeout=1800) text_file = ocr_result.get("output_file") if ocr_result.get("success") else None if text_file: result["stages"].append({"stage": "ocr", "file": text_file}) + else: + print(f"OCR处理未生成文件") else: - print(f"\n无字幕文件,跳过OCR处理") + print(f"无字幕文件,跳过OCR处理") # 深度分析 print(f"\n{'='*50}")