
graphify 音视频转写管线用 Whisper 领域提示把 MP4/MP3 纳入知识图谱【免费下载链接】graphifyTurn any codebase, with its docs, SQL schemas, configs, and PDFs, into a queryable knowledge graph. A /graphify skill for Claude Code, Cursor, Codex, and Gemini CLI: local deterministic AST parsing, every edge explained, no vector store.项目地址: https://gitcode.com/GitHub_Trending/graph/graphify本文围绕 graphify 技能参考文档 transcribe.mdStep 2.5 音视频转写流程展开讲解当detect检测到视频/音频文件时如何先自拟一句 Whisper 领域提示、再以导出环境变量的方式驱动 graphify/transcribe.py 完成批量转写并说明转写结果如何作为文档进入后续语义提取。读完你可以完整掌握 graphify 中音视频 → 文本 → 图谱的入口链路、GRAPHIFY_WHISPER_MODEL/GRAPHIFY_WHISPER_PROMPT两个环境变量的正确用法以及缓存、容错、URL 下载等底层实现细节。Step 2.5 在管线中的位置仅当检测到视频才执行graphify 的核心管线是detect文件分类→ Step 2.5音视频转写条件触发→ Step 3结构/语义提取。参考文档开篇就明确了加载条件Load this only whendetectreported one or morevideofiles. A corpus with no video never reads this.也就是说纯代码或纯文档的语料库永远不会读取这份参考转写步骤会被整体跳过。这一点在主技能文档 skill-amp.md 的 Step 2.5 章节中同样被强调Skip this step entirely ifdetectreturned zerovideofiles.并且文档注释说明了视频的归宿——Video is transcribed to a document in Step 2.5 first.即转写完成后转写文本按文档doc文件对待进入 Step 3B 的语义子代理调度。哪些文件会被归入video类别从源码看graphify/detect.py 定义了分类集合VIDEO_EXTENSIONS {.mp4, .mov, .webm, .mkv, .avi, .m4v, .mp3, .wav, .m4a, .ogg}注意该集合实际覆盖视频 音频两种类型graphify/transcribe.py 中的VIDEO_EXTENSIONS与之一致并有测试 tests/test_transcribe.py 固定了这一约定。另外detect.py 的词数统计逻辑 中video类别不计入total_wordsif ftype ! FileType.VIDEO: total_words _wc(p)因为音视频没有可读取的文本词频——这也正是必须先转写、再当作文档处理的根本原因。detect的输出会落盘为graphify-out/.graphify_detect.json其中files字段按类型分组code、document、paper、image、video后续所有步骤包括转写都从这个 JSON 读取文件清单。Whisper 提示策略从 god nodes 自拟一句领域提示原始音频对 Whisper 来说是零上下文的initial_prompt领域提示能显著改善术语识别与断句。文档给出的策略是不需要额外 API 调用——你宿主 Agent 本身就是语言模型直接从graphify-out/.graphify_detect.json或上次运行遗留的分析文件里读取 god nodes连接度最高的节点标签自己写一句领域提示。文档给出了两个示例标签transformer, attention, encoder, decoder→Machine learning research on transformer architectures and attention mechanisms. Use proper punctuation and paragraph breaks.标签kubernetes, deployment, pod, helm→DevOps discussion about Kubernetes deployments and Helm charts. Use proper punctuation and paragraph breaks.特例如果语料库只有视频文件、没有其他任何文档/代码没有 god nodes 可用则退回通用兜底提示Use proper punctuation and paragraph breaks.这个自拟提示策略在源码层面有完整对应。graphify/transcribe.py 中的build_whisper_prompt()实现了同一逻辑链def build_whisper_prompt(god_nodes: list[dict]) - str: if not god_nodes: return _FALLBACK_PROMPT override os.environ.get(GRAPHIFY_WHISPER_PROMPT) if override: return override labels [n.get(label, ) for n in god_nodes[:10] if n.get(label)] if not labels: return _FALLBACK_PROMPT topics , .join(labels[:5]) return fTechnical discussion about {topics}. Use proper punctuation and paragraph breaks.从源码结构看优先级是GRAPHIFY_WHISPER_PROMPT环境变量 前 5 个 god node 标签拼出的主题句 兜底常量_FALLBACK_PROMPTtranscribe.py#L14-L16其值正是文档要求的Use proper punctuation and paragraph breaks.。这与 tests/test_transcribe.py 中的三组测试一一对应空节点返回兜底、环境变量短路、节点标签生成主题句且无label键的节点会被安全跳过。完整转写命令两个必须 export 的环境变量参考文档给出的标准执行方式是两步走第 1 步——写提示并导出。提示必须以GRAPHIFY_WHISPER_PROMPT这个名字导出文档特别强调名字必须精确且必须export因为它是子 Python 进程要读取的环境变量export GRAPHIFY_WHISPER_PROMPT你在第 1 步自拟的一句领域提示第 2 步——执行批量转写export GRAPHIFY_WHISPER_MODELbase # 或用户通过 --whisper-model 传入的值必须 export export GRAPHIFY_WHISPER_PROMPT你在第 1 步自拟的一句领域提示 $(cat graphify-out/.graphify_python) -c import json, os, sys from pathlib import Path from graphify.transcribe import transcribe_all detect json.loads(Path(graphify-out/.graphify_detect.json).read_text(encoding\utf-8\)) video_files detect.get(files, {}).get(video, []) prompt os.environ.get(GRAPHIFY_WHISPER_PROMPT, Use proper punctuation and paragraph breaks.) transcript_paths transcribe_all(video_files, initial_promptprompt) # 从 Python 写 JSON而不是 shell 的 重定向transcribe_all/Whisper # 会向 stdout 打印进度重定向会污染 JSON 文件#1392。 Path(graphify-out/.graphify_transcripts.json).write_text(json.dumps(transcript_paths, ensure_asciiFalse), encoding\utf-8\) print(fTranscribed {len(transcript_paths)} file(s), filesys.stderr) 这段命令里有几个值得注意的工程细节$(cat graphify-out/.graphify_python)graphify 管线约定用该文件记录本次运行使用的解释器路径保证后续 Python 片段与 detect 步骤运行在同一环境为什么不能用 shell重定向transcribe_all与 Whisper 本身会向 stdout 打印进度日志若把整个-c输出重定向到 JSON 文件进度行会混进 JSON 造成损坏。文档明确要求 JSON 由 Python 的Path.write_text写出进度提示走 stderr对应 issue #1392 的修复说明;initial_prompt全批次共享从 transcribe_all 的源码 看提示built once from corpus god nodes一次构建、所有文件复用不会逐文件重新生成。转写完成后的收尾动作文档原文要求从graphify-out/.graphify_transcripts.json读取转写文本路径在 Step 3B 调度语义子代理之前把它们追加进文档列表打印形如Transcribed N video file(s) - treating as docs的汇总某个文件转写失败时打印警告并继续处理其余文件而非中断整个管线。源码纵深transcribe() 的缓存、推理参数与 URL 支持参考文档只展示了批量入口transcribe_all单文件实现 transcribe() 里藏着几个决定行为的关键点1. 幂等缓存。转写产物固定命名为输出目录/原文件名stem .txt默认输出目录由 graphify/paths.py 的out_path(transcripts)解析即graphify-out/transcripts/。若该文件已存在且未传forceTrue直接返回缓存路径、不加载 Whisper 模型transcribe.py#L141-L143。测试 test_transcribe_uses_cache 与 test_transcribe_force_reruns 分别验证了命中缓存直接返回和forceTrue强制重跑两种路径。这意味着重复运行/graphify不会重复消耗 CPU 转写。2. CPU 友好的推理配置。实际推理参数见 transcribe.py#L150-L155model WhisperModel(model_name, devicecpu, compute_typeint8) segments, info model.transcribe( str(audio_path), beam_size5, initial_promptprompt, )固定devicecpucompute_typeint8配合beam_size5的束搜索——这是在无 GPU 环境技能管线常见于用户本地终端下的保守配置模型名默认base由_model_name()从GRAPHIFY_WHISPER_MODEL读取transcribe.py#L14-L20。3. 文档未展开但源码支持的能力URL 直转。transcribe() 会通过 is_url() 判断输入是本地路径还是 URL若是 URL则调用 download_audio() 用 yt-dlp 只下载音频流bestaudio[extm4a]/bestaudio/best不启用 ffmpeg 后处理。下载前会先经过 graphify/security.py 的validate_url拦截内网 IP 与非法协议下载文件以 URL 的 SHA-1 前 12 位命名yt_hash.m4a命中已存在文件时直接复用缓存。转写结果中还会打印检测到的语言与 segment 数lang..., N segments。4. 批处理容错。transcribe_all() 对每个文件try/except失败时打印warning: could not transcribe {vf}: {exc}并跳过返回成功文件的转写路径列表——这正是文档If transcription fails for a file, print a warning and continue with the rest要求的语义测试 test_transcribe_all_skips_failed 验证了单文件抛异常 → 返回空列表但不崩溃。模型选择与依赖安装模型默认base。技能主文档 skill-amp.md 给出了用法示例/graphify path --whisper-model medium更大模型换取更高转写准确率。文档要求若用户传了--whisper-model name必须在运行转写命令前执行export GRAPHIFY_WHISPER_MODELname——再次强调必须export因为_model_name()读的是子进程的环境变量纯 shell 赋值不 export子进程看不到。依赖pyproject.toml 定义了 video 可选依赖组video [faster-whisper; python_version 3.11, yt-dlp2026.6.9]即 faster-whisper 要求 Python ≥ 3.11yt-dlp 仅 URL 下载场景需要。若未安装transcribe.py 在导入时抛出带明确指引的ImportErrorRun: pip install graphifyy[video]测试 test_transcribe_missing_faster_whisper 确认该异常会向上传播。验证要点小结如需确认本机行为与文档一致可关注以下仓库内证据只读检查即可关注点依据视频扩展名集合固定为 10 种graphify/transcribe.py#L11、tests/test_transcribe.py#L22-L27提示优先级env god nodes 兜底graphify/transcribe.py#L103-L115、tests/test_transcribe.py#L40-L61缓存命中不加载模型 /force重跑tests/test_transcribe.py#L68-L100单文件失败不中断批次tests/test_transcribe.py#L136-L147detect 分类与 video 不计词数graphify/detect.py#L49、graphify/detect.py#L1929-L1930最后说明一点transcribe.md并非 amp 平台独有——逐字节比对可确认它与 graphify/skills/claude/references/transcribe.md 等其余 15 个 Agent 平台Claude Code、Codex、Cursor、Gemini CLI、Kiro 等目录下同名参考完全相同。从源码结构看这是 graphify 技能分发机制的一部分各平台共享同一套参考文档转写步骤的行为在所有宿主 Agent 中保持一致。【免费下载链接】graphifyTurn any codebase, with its docs, SQL schemas, configs, and PDFs, into a queryable knowledge graph. A /graphify skill for Claude Code, Cursor, Codex, and Gemini CLI: local deterministic AST parsing, every edge explained, no vector store.项目地址: https://gitcode.com/GitHub_Trending/graph/graphify创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考