Files
aigc-home/docs/hel-892/asr-document-evidence/build_definition.py
T

599 lines
28 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Bind two ASR editorial documents to immutable sources; no upstream execution."""
from __future__ import annotations
import copy
import hashlib
import json
import runpy
from pathlib import Path
REPO = Path(__file__).resolve().parents[3]
OUT = Path(__file__).resolve().parent
PREFIX = "example_ComfyUI_workflows/1-语音生成/"
PATHS = [PREFIX + "Qwen3-ASR-语音转文字.json", PREFIX + "Qwen3-ASR-Subtitle语音转字幕.json"]
audio = runpy.run_path(str(OUT.parent / "audio-document-evidence/build_definition.py"))
canonical = audio["canonical"]
def build(path):
raw = (REPO / path).read_bytes()
source = json.loads(raw)
subtitle = path == PATHS[1]
fields, refs = [], []
def ref(filename, start, end, claim):
directory = (
"serialization-evidence" if filename.startswith("src__") else "structure-reference"
)
root = OUT.parent / directory
item = next(
s
for s in json.loads((root / "sources.json").read_bytes())["sources"]
if s["local_file"] == filename
)
content = (root / filename).read_bytes()
assert hashlib.sha256(content).hexdigest() == item["sha256"]
assert 1 <= start <= end <= len(content.decode().splitlines())
refs.append(
{
**{k: item[k] for k in ("id", "commit", "file", "sha256", "url")},
"license": item.get("license", "沿用来源manifest"),
"local_file": "../" + directory + "/" + filename,
"lines": [start, end],
"claim": claim,
}
)
return len(refs) - 1
def field(
node,
offset,
name,
label,
typ,
unit,
limits,
effect,
default,
evidence,
role="scalar",
execution=None,
):
idx = next(i for i, n in enumerate(source["nodes"]) if n["id"] == node)
n = source["nodes"][idx]
value = n["widgets_values"][offset]
fields.append(
dict(
node_id=str(node),
class_type=n["type"],
field=name,
label=label,
type=typ,
value=value,
json_type=type(value).__name__,
pointer=f"/nodes/{idx}/widgets_values/{offset}",
unit=unit,
limits=limits,
effect=effect,
schema_default=default,
evidence=evidence,
role=role,
execution_note=execution
or "固定参考恢复后作为标量进入前端输入;目标执行与实际效果未验证。",
)
)
# Reuse reviewed LoadAudio semantics, rebind each exact value and pointer.
old = audio["build"](audio["PATHS"][0])
refs.extend(copy.deepcopy(old["sources"]))
load_id = 6 if subtitle else 5
load_idx = next(i for i, n in enumerate(source["nodes"]) if n["id"] == load_id)
for f in old["fields"]:
if f["node_id"] != "1":
continue
f = copy.deepcopy(f)
offset = int(f["pointer"].split("/")[-1])
f.update(
node_id=str(load_id),
pointer=f"/nodes/{load_idx}/widgets_values/{offset}",
value=source["nodes"][load_idx]["widgets_values"][offset],
)
f["json_type"] = type(f["value"]).__name__
fields.append(f)
# Keep only cited load evidence; remove MP3-only references.
keep = sorted({i for f in fields for i in f["evidence"]})
remap = {old: new for new, old in enumerate(keep)}
refs[:] = [refs[i] for i in keep]
for f in fields:
f["evidence"] = [remap[i] for i in f["evidence"]]
qfile = "qwen-b037d7be.py"
schema = ref(
qfile,
582 if subtitle else 514,
630 if subtitle else 547,
"具体类注册schema、可选字段构造顺序及执行默认;不是照源inputs数组猜字段",
)
config = ref(qfile, 37, 125, "语言静态枚举与配置可覆盖的模型/对齐器/默认值")
dtype = ref(qfile, 317, 396, "模型解析/精度设备分支、缓存键与from_pretrained参数")
infer = ref(
qfile,
631 if subtitle else 548,
712 if subtitle else 579,
"实际转写、context、语言、返回值、卸载与字幕文件保存条件",
)
group = ref(qfile, 421, 494, "标点/间隔/字符分组与SRT文件格式;不保证硬截断长度")
restore = ref(
"ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__LGraphNode.ts",
867,
922,
"恢复跳过widget.serialize=false;保存按原控件下标,null占位不能自行丢弃",
)
execution = ref(
"1.37.11__src__utils__executionUtil.ts",
85,
127,
"执行检查options.serialize、同名覆盖,随后物理边覆盖输入",
)
app = ref(
"src__services__litegraphService.ts",
143,
230,
"具体控件构造及getOrderedInputSpecs;schema字段恢复而非按源inputs列表猜字段",
)
ordering = ref(
"src__workbench__utils__nodeDefOrderingUtil.ts",
15,
52,
"input_order存在时按required/optional顺序,否则Object.values;不采用UI插槽位置猜字段",
)
for node in [9] if subtitle else [32, 34]:
names = (
[
"model",
"precision",
"attention",
"forced_aligner",
"language",
"hints",
"output_format",
"output_path",
"split_mode",
"max_gap_sec",
"max_chars",
"max_inference_batch_size",
"max_new_tokens",
"unload_models",
]
if subtitle
else ["model", "precision", "language", "hints", "unload_models"]
)
info = {
"model": (
"识别模型选择",
"动态COMBO / STRING",
"不适用",
"配置models键构成动态列表;本参考回退Qwen/Qwen3-ASR-0.6B和1.7B,目标配置/权重存在未知。",
"决定模型解析与缓存身份;本图0.6B是源选择字符串,不证明模型已安装、能加载或识别质量。",
"schema读defaults.repo_id,回退Qwen/Qwen3-ASR-0.6B;函数同名回退。",
[config, dtype],
),
"precision": (
"识别精度",
"静态COMBO / STRING",
"不适用",
"bf16、fp16、fp32;设备精度支持和显存未知。",
"bf16在mps分支改用float16,其它设备为bfloat16;fp16为float16,否则float32。不保证速度、准确率或资源占用。",
"schema读配置precision,回退bf16;函数回退bf16。",
[config, dtype],
),
"attention": (
"注意力后端",
"静态COMBO / STRING",
"不适用",
"auto、flash_attention_2、sdpa、eager;后端是否安装/设备支持未知。",
"auto不传attn_implementation,其它值传给识别模型及对齐器构造;不保证可用或更快。",
"schema读配置attention,回退auto;函数回退auto。",
[config, dtype],
),
"forced_aligner": (
"时间戳对齐模型",
"动态COMBO / STRING",
"不适用",
(
"配置aligners键动态列表;固定回退None和Qwen/Qwen3-ForcedAligner-0.6B。"
"该固定b037列表、源图和配套均无-hf;其它版本曾有-hf差异不能套本版本,目标就绪未知。"
),
"非空且不等于None字符串时解析对齐器路径并传forced_aligner;源无-hf名称逐字保留,属于此固定回退列表但不证明目标选项或文件存在。时间戳精度未知。",
"schema配置forced_aligner回退Qwen/Qwen3-ForcedAligner-0.6B(无-hf);函数同名回退,与本固定回退列表一致。",
[config, dtype, infer],
),
"language": (
"识别语言",
"静态COMBO / STRING",
"不适用",
(
"固定枚举:auto、Chinese、English、Cantonese、Arabic、German、Frenc"
"h、Spanish、Portuguese、Indonesian、Italian、Korean、Russian、"
"Thai、Vietnamese、Japanese、Turkish、Hindi、Malay、Dutch、Swed"
"ish、Danish、Finnish、Polish、Czech、Filipino、Persian、Greek、"
"Hungarian、Macedonian、Romanian;不据音频名判断语言。"
),
"auto转为language=None交识别器,其它字符串指定语言;输出检测语言/识别正确性不保证。",
"schema读配置language,回退auto;函数回退auto。",
[config, infer],
),
"hints": (
"识别术语提示",
"STRING",
"不适用",
"多行字符串,无schema长度限制;保留字面反斜杠及换行,不执行或增强提示内容。",
"实现仅在运行时strip字符串作为context,空结果传None。提示可能影响识别,不保证术语或大小写正确;两ASR支路独立,32为空串,34非空。"
if not subtitle
else (
"运行时strip字符串作为context,空结果传None;节点9本保存值被Primitive7物理线覆盖,即"
"使两原字符串相同也只算一个最终hints。提示不保证识别正确。"
),
"schema/函数默认空字符串;本图现值另列,不用默认覆盖。",
[infer],
),
"output_format": (
"字幕文件保存格式",
"静态COMBO / STRING",
"不适用",
"none、txt、srt;只选择文件保存,不改变SUBTITLES文本出口格式。",
"源none不进入文件写入分支;正常转写仍生成字幕行字符串,OUTPUT_PATH返回空字符串,不生成可下载字幕响应。改txt/srt才请求写文件,真实目录/权限未知。",
"schema/函数默认none。",
[infer, group],
),
"output_path": (
"字幕保存路径请求",
"STRING",
"不适用",
"schema无长度限制;相对路径、空串或绝对路径的处理仅在output_format非none时生效。",
(
"源空字符串且format=none不写字幕文件,正常返回file_path为空;若请求保存,先strip,相对"
"路径基于ComfyUI输出目录并可能加默认文件名/扩展。路径字符串不证明文件存在。"
),
"schema/函数默认空字符串。",
[infer],
),
"split_mode": (
"字幕分句策略",
"静态COMBO / STRING",
"不适用",
(
"六枚举:split_by_punctuation_or_pause_or_length、split_by_pu"
"nctuation_or_pause、split_by_punctuation_or_length、split"
"_by_punctuation、split_by_pause、split_by_length。"
),
"按模式启用句尾标点、停顿阈值、累计字符长度条件;任一启用条件满足则起新组。时间戳或分组为空时字幕可为空;不保证句数、行长或对齐效果。",
"schema/函数默认split_by_punctuation_or_pause_or_length。",
[group, infer],
),
"max_gap_sec": (
"字幕分组停顿阈值",
"FLOAT",
"秒",
"schema 0.0..8.0,前端step=0.1;后端分组直接比较,无同等范围钳制。",
"相邻时间戳start减当前组end严格大于本阈值,且模式启用pause时拆组;源浮点0.6不是保证的静音检测精度。",
"schema/函数默认0.6。",
[group, infer],
),
"max_chars": (
"字幕累计字符阈值",
"INT",
"字符数(Python len)",
"schema整数0..200,未显式step;0关闭长度条件。仅模式启用length有效,非硬截断。",
"累计两段文本长度超过阈值时在下一段前拆组;已有单段可能超过限制,不能保证每行最多40字。",
"schema默认40,transcribe函数回退60;本图明确保存40。",
[group, infer],
),
"max_inference_batch_size": (
"推理与对齐批大小",
"INT",
"批内项数",
"schema整数1..256,未显式step;源码int转换传模型,不等于资源安全上界。",
"作为模型构造参数及缓存键;调整可能改变内存压力/吞吐,32不保证避免OOM。目标设备与模型依赖未知。",
"schema/函数/加载函数默认32。",
[dtype],
),
"max_new_tokens": (
"每块新增token上限",
"INT",
"token数",
"schema整数1..2048,未显式step;int转换传模型,实际模型限制未知。",
"参与缓存键并传from_pretrained;本图256为请求上限,不保证文本长度、完整度、速度或内存消耗。",
"schema/函数/加载函数默认256。",
[dtype],
),
"unload_models": (
"识别后卸载缓存",
"BOOLEAN",
"不适用",
"true/false;只描述本插件缓存和释放请求,不保证全部显存归还。",
"true在正常识别返回前clear插件缓存并尝试soft_empty_cache,异常被忽略;false保留缓存。早退/报错路径不保证经过卸载。",
"schema/函数默认true;源true保持布尔。",
[infer],
),
}
for offset, name in enumerate(names):
label, typ, unit, limits, effect, default, ev = info[name]
role = "linked" if subtitle and name == "hints" else "scalar"
note = (
"保存hints被link14的Primitive7槽0 → 9.hints覆盖;运行字符串取自7,不双算最终输入。"
if role == "linked"
else None
)
field(
node,
offset,
name,
label,
typ,
unit,
limits,
effect,
default,
[schema, app, ordering, restore, execution, *ev],
role,
note,
)
preview = ref(
"ComfyUI_frontend__4bf6a196__src__extensions__core__previewAny.ts",
14,
83,
"旧前端创建两preview DOM控件和previewMode;仅widget.serialize=false,onExecuted写ui.text",
)
backend = ref(
"ComfyUI__09725967__comfy_extras__nodes_preview_any.py",
8,
37,
"PreviewAny后端只有source输入;返回ui.text,不返回文件描述符",
)
dom = ref(
"ComfyUI_frontend__4bf6a196__src__scripts__domWidget.ts",
142,
148,
"DOM getter无getValue返回空串,不恢复源null为文本内容",
)
boolean = ref(
(
"ComfyUI_frontend__4bf6a196__src__renderer__extensions__"
"vueNodes__widgets__composables__useBooleanWidget.ts"
),
7,
31,
"previewMode构造默认false与toggle,没有把源null改布尔",
)
base = ref(
"ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__widgets__BaseWidget.ts",
99,
107,
"基础value setter原样赋值;恢复null不冒充默认false",
)
for node in [1, 2, 3, 4] if subtitle else [24, 35]:
field(
node,
0,
"previewMode",
"文本显示模式保存态",
"保存JSON null / 参考BOOLEAN控件",
"不适用",
"构造默认false,true/false用于Markdown/Plaintext;本图实际保存null,不强转为false。",
(
"恢复跳过两个widget.serialize=false的preview,首保存项null赋给previewM"
"ode;graphToPrompt检查另一options.serialize属性,保留previewMode="
"null及同名preview空串。后端只声明source,不能把它称后端运行参数。"
),
"前端构造false;源首项null仍原样保存。",
[preview, restore, execution, boolean, base],
"frontend",
"前端显示状态;参考wire仍含previewMode=null及preview空串,非后端schema参数,未知扩展影响。",
)
for offset in (1, 2):
field(
node,
offset,
f"saved_position_{offset}",
f"位置{offset}未恢复占位",
"JSON null",
"不适用",
"无可证明的字段默认/单位/范围;仅保留源位置null,不按三控件顺序强具名。",
(
"旧前端恢复仅消费首项,其余两个null未恢复到控件;保存按控件原下标可产生空洞,不代表两段空转写文本。两pre"
"view DOM控件的执行getter为空串且后者覆盖前者;真实内容待ui.text回调。"
),
"不适用:未恢复位置占位,不是schema参数。",
[preview, restore, execution, dom, backend],
"frontend",
"仅源保存位置,占位不直接进入最终输入;不能与执行preview空串混同。",
)
flow = []
if subtitle:
primitive = ref(
"1.37.11__src__extensions__core__widgetInputs.ts",
28,
93,
"Primitive虚拟标记与applyToGraph按目标widget.name复制值",
)
primitive_widget = ref(
"1.37.11__src__extensions__core__widgetInputs.ts",
180,
243,
"读取目标hints schema并构造Primitive STRING value控件",
)
field(
7,
0,
"hints",
"虚拟提示字符串来源",
"STRING",
"不适用",
"目标hints为多行字符串;源Run widget replace on values=false,不做替换或增强。",
"Primitive7是虚拟值来源,link14送到9.hints;其保存字符串与9内保存值恰同仍按物理来源解释,折叠后只有6个实体,原图仍7源节点。",
"由目标hints控件创建,目标schema默认空串;此源为明确非空原字符串。",
[primitive, primitive_widget, execution, schema, restore],
"virtual",
"虚拟Primitive来源,固定参考折叠到9.hints,非额外后端节点或第二个最终hints。",
)
manifest = json.loads((OUT.parent / "supplied-api/manifest.json").read_bytes())
case = next(c for c in manifest["cases"] if c["id"] == "02")
export = OUT.parent / "supplied-api" / case["export_file"]
assert hashlib.sha256(export.read_bytes()).hexdigest() == case["export_sha256"]
companion = {
k: case[k]
for k in (
"id",
"export_file",
"export_sha256",
"attachment_id",
"received_at",
"source_comment_id",
"exported_at",
"frontend_version",
"node_versions",
"source_export_equivalence_verified",
)
}
api = json.loads(export.read_bytes())
companion["actual_export_node9_inputs"] = api["9"]["inputs"]
companion["actual_export_preview_sources"] = {
k: api[k]["inputs"]["source"] for k in ["1", "2", "3", "4"]
}
flow = [
"用途:读取音频生成识别文字、分组字幕与检测语言的字符串;素材ComfyUI-qwenasr_00003_.mp3只是引用,可达性/权重/媒体长度未知。",
(
"link13:6槽0 AUDIO → 9.audio;link14:7槽0 STRING → 9.hints("
"覆盖9保存hints,即使字符串恰同)。Primitive7是虚拟节点,折叠参考6实体不等于源7节点。"
),
(
"四STRING出口:link15 9槽0 TEXT → 4.source;link16 9槽1 SUBTITL"
"ES → 2.source;link17 9槽2 LANUGAGE → 3.source;link18 9槽3"
" OUTPUT_PATH → 1.source。保留原LANUGAGE拼写,其槽2为检测语言。"
),
(
"正常识别时SUBTITLES由每组start/end保留两位小数及text拼行,不是SRT文件格式。源outp"
"ut_format=none、output_path为空:不写字幕文件,OUTPUT_PATH返回空字符串,P"
"reviewAny的ui.text不是下载文件描述符。没有时间戳时字幕可为空;audio_data为空的源码早"
"退只返回三个空串,与四出口声明不一致,不冒充实跑已通过。"
),
"API配套核对(02.api.json,SHA256 "
+ case["export_sha256"]
+ (
";历史library-reference-evidence及case04-batch):9额外normaliz"
"e_text=true不在UI保存/固定b037定义;6缺audioUI而固定前端wire附加空串,四Prev"
"iew仅source且缺preview空串/previewMode=null,并有标题差异。四出口槽在API与"
"UI均1←3/2←1/3←2/4←0,本固定b037默认/列表、UI和API的forced_aligner均无"
"-hf,不能从其它版本摘要抄成出口或模型名差异。逐源保留,"
"不套同ID API值或声称等价;normalize_"
"text没有虚构UI位置/默认。"
),
(
"计数口径:固定前端24最终标量包含14字幕字段(hints取7)、LoadAudio2项及四Preview各2"
"附加值,不能都称后端参数;仅前端控制9项是upload与8个未恢复占位。49本批保存值中本图30项独立计数:3"
" LoadAudio、14字幕、1 Primitive、12 Preview;虚拟来源/连线覆盖与显示占位独立"
"。companion_unverified/output_unconfirmed、空输出映射继续保留。"
),
]
steps = [
"未来获准环境中核对固定参考与真实插件、前端、模型/对齐器及音频素材;本轮不推理、不下载。",
"选择6音频,核对6→9.audio与7→9.hints;提示只保留原字符串,9内部hints被线覆盖。",
"逐项核对9的模型/精度/attention/对齐器/语言及分句阈值和资源请求;模型名与固定/配套同为无-hf,目标选项仍须核对,不能替换当前值。",
"保留none与空路径时只核对四文本出口及其槽位、ui.text显示;需另行获准保存/运行后核对实际history与文件,不能把空路径当下载。",
"对照独立case02差异,不把标题差异或出口槽一致当运行等价;保持停用、说明未定稿、依赖未检查与实跑未验证。",
]
scalars, linked, frontend_only = 24, 1, 9
else:
flow = [
"用途:同一音频送两条独立识别支路比较源配置,32.hints为空、34.hints非空;素材只是文件名引用,模型/素材存在与识别质量未知。",
(
"link49:5槽0 AUDIO → 32.audio;link52:5槽0 AUDIO → 34.audio。"
"两个识别器分别保留,不合并。"
),
(
"link50:32槽0 TEXT → 24.source;link51:34槽0 TEXT → 35.sour"
"ce。两个文本预览分别接对应结果;PreviewAny后端返回ui.text,由旧前端两preview显示,未"
"构成文件下载。"
),
(
"MarkdownNote33原注释建议术语/品牌/大小写提示,仅为作者源注释,不证明hints能强制正确。注释"
"全文在源文件注释区逐字保留,不计运行参数或保存控件49项。"
),
(
"计数口径:固定前端16最终标量含两ASR各5、LoadAudio2、两Preview各2;后端参数与附加UI值"
"分列,仅前端控制5项是upload与四未恢复占位。本图19保存值:LoadAudio3、两ASR共10、两Pr"
"eview共6;另有1条MarkdownNote。原图6源节点/4边,参考候选5实体仅表示排除虚拟注释,未证A"
"PI等价或实跑。"
),
]
companion = None
steps = [
"未来获准环境中核对插件提供方/版本、模型文件与音频引用;本轮不加载模型或处理媒体。",
"在5选择音频,核对两个AUDIO分支分别进入32和34,不合并识别器。",
"分别核对两路model/precision/auto语言、空与非空hints和卸载选项;源注释建议不作为识别保证。",
"获准实跑后分别查看24与35的文本及真实history,核对术语/语言/质量;当前没有API配套且未执行,保持停用、未定稿和依赖未检查。",
]
scalars, linked, frontend_only = 16, 0, 5
fields.sort(
key=lambda f: tuple(
int(v) for v in (f["pointer"].split("/")[2], f["pointer"].split("/")[4])
)
)
result = dict(
notice="固定版本参考说明:前端1.37.11与core0.11.0按声明核对;Qwen节点提供方/版本未声明,采用b037d7be显式参考假设;UE扩展与目标环境未核对",
source_path=path,
source_sha1=hashlib.sha1(raw).hexdigest(),
source_sha256=hashlib.sha256(raw).hexdigest(),
canonical_sha256=hashlib.sha256(canonical(source)).hexdigest(),
versions=[
(
"前端声明1.37.11,固定4bf6a1960028cc5cda57d48f9fb01a74dfaade43;"
"LoadAudio/PreviewAny声明core0.11.0,固定09725967cf76304371c3"
"90ca1d6483e04061da48。"
),
(
"ASR/Subtitle未声明提供方或节点版本;仅参考1038lab/ComfyUI-QwenASR@b037"
"d7be121111a1ba6f40a4d99f6b43ac6411b6,不能补为用户实际来源;UE扩展版本记"
"录不证明扩展改写已核对;两图具体记录分别保留于源文,不据此添加已知插件身份。"
),
"模型/动态列表/目标设备/真实history未知;固定源码可证静态行为不等于实际兼容或运行质量。",
],
counts=dict(
saved_fields=len(fields),
final_scalars=scalars,
linked_saved_fields=linked,
frontend_only=frontend_only,
physical_edges=len(source["links"]),
),
fields=fields,
sources=refs,
flow=flow,
flow_evidence=list(range(len(refs))),
steps=steps,
)
if companion:
result["companion_difference"] = companion
return result
def main():
target = REPO / "calliope-backend/src/calliope/comfyui/source_reviews.json"
reviews = json.loads(target.read_bytes())
for i, path in enumerate(PATHS):
block = build(path)
assert reviews[path]["source_sha"] == block["source_sha1"]
reviews[path]["fixed_version_document"] = block
(OUT / f"definition-{i}.json").write_text(
json.dumps(block, ensure_ascii=False, indent=2) + "\n"
)
print(path, hashlib.sha256(canonical(block)).hexdigest())
target.write_text(json.dumps(reviews, ensure_ascii=False, indent=2) + "\n")
if __name__ == "__main__":
main()