115 lines
4.9 KiB
Python
115 lines
4.9 KiB
Python
"""对选中镜头的已有净音轨重新做语音检查。这个计划仅能创建音频检查任务。"""
|
|
|
|
from copy import deepcopy
|
|
|
|
from app.adapters.provider.native_av import alignment_enabled
|
|
from app.core.errors import fail
|
|
from app.domain.continuity import compile_story_timing
|
|
from app.domain.native_av import source_audio_matches_video
|
|
from app.domain.stories import digest
|
|
from app.services.editor_media import assigned_utterance_ids
|
|
|
|
|
|
async def plan_source_inspection(session, draft, manifest, body, settings):
|
|
from app.services.orchestration.dialogue_engine import _recipe
|
|
from app.services.orchestration.editor_engine import _asset
|
|
from app.services.orchestration.native_dialogue_engine import _audio_review_context
|
|
|
|
body = body.model_dump(exclude_unset=True) if hasattr(body, "model_dump") else body
|
|
targets = body.get("targets", [])
|
|
if (
|
|
len(targets) != 1
|
|
or body.get("force")
|
|
or targets[0] not in {"native_report:" + sid for sid in manifest["shot_ids"]}
|
|
):
|
|
fail(422, "invalid_target", "仅分析已有原声时请选择一个镜头的语音报告")
|
|
target = targets[0]
|
|
sid = target.split(":", 1)[1]
|
|
issues, recipes, hashes = [], [], {}
|
|
spec = manifest["spec"]
|
|
dialogue = spec.get("dialogue", {})
|
|
bindings = manifest["bindings"]
|
|
video, audio = (bindings.get(prefix + sid) or {} for prefix in ("video:", "native_audio:"))
|
|
aligned_capability = alignment_enabled(settings, getattr(settings, "_native_av_upstream", {}))
|
|
|
|
def issue(code, message):
|
|
issues.append(dict(code=code, unit_id=sid, message=message))
|
|
|
|
if not dialogue.get("enabled") or dialogue.get("generation") != "native_av":
|
|
issue("native_source_required", "请选择已启用原生对白的镜头")
|
|
elif not source_audio_matches_video(audio, video):
|
|
issue("caption_audio_missing", "缺少与所选视频同源的 48 kHz 未混音对白,无法仅分析原声")
|
|
else:
|
|
for binding, kind in ((video, "video"), (audio, "audio")):
|
|
if not await _asset(session, draft.owner_id, binding, settings, kind):
|
|
issue("caption_source_changed", "已选原视频或净音轨不可访问或校验失败")
|
|
break
|
|
hashes[binding["asset_id"]] = binding["sha256"]
|
|
if (bindings.get(target) or {}).get("locked"):
|
|
issue("caption_report_locked", "语音报告已锁定,请先解除保护")
|
|
if not aligned_capability:
|
|
issue("caption_analysis_unavailable", "已有原声音频识别能力尚未就绪")
|
|
if not issues:
|
|
shot = next(s for s in spec["shots"] if s["id"] == sid)
|
|
sequences = {q["id"]: q for q in dialogue["sequences"]}
|
|
by_uid = {u["id"]: u for u in dialogue["utterances"]}
|
|
lines = [by_uid[uid] for uid in assigned_utterance_ids(shot, sequences)]
|
|
if (
|
|
not lines
|
|
or len({u["speaker_id"] for u in lines}) != 1
|
|
or shot["performance"].get("dialogue_staging") == "two_person_turns"
|
|
):
|
|
issue("caption_single_speaker_required", "请选择已分配单人台词的原声镜头")
|
|
else:
|
|
speaker = lines[0]["speaker_id"]
|
|
expected = "".join(u.get("spoken_text") or u["text"] for u in lines)
|
|
recipes.append(
|
|
_recipe(
|
|
"inspect_source",
|
|
"audio.dialogue.inspect",
|
|
sid,
|
|
target,
|
|
forced=True,
|
|
inputs=dict(expected_text=expected, speaker_id=speaker),
|
|
parameters=dict(
|
|
profile="dialogue-audio-v1",
|
|
sample_rate=48000,
|
|
native_av_policy="native_av_v1",
|
|
),
|
|
context=_audio_review_context(audio["sha256"], expected, speaker),
|
|
)
|
|
)
|
|
signature = digest(
|
|
dict(
|
|
operation="caption-source-inspect-v1",
|
|
manifest=manifest,
|
|
targets=targets,
|
|
recipe=recipes,
|
|
hashes=hashes,
|
|
issues=issues,
|
|
execution_mode=body.get("execution_mode", "interactive"),
|
|
output_folder_id=body.get("output_folder_id", draft.folder_id),
|
|
capable=aligned_capability,
|
|
)
|
|
)
|
|
return dict(
|
|
output_goal="caption_inspect",
|
|
source_version=draft.version,
|
|
plan_hash=signature,
|
|
steps=[dict(key=r["key"], kind=r["kind"], unit_id=sid, status="generate") for r in recipes],
|
|
issues=issues,
|
|
_recipes=recipes,
|
|
_capabilities=dict(reference_shas=hashes),
|
|
_prepared=dict(
|
|
production_materialized=True,
|
|
effective_manifest=deepcopy(manifest),
|
|
timing=compile_story_timing(spec),
|
|
utterances=[],
|
|
issues=[],
|
|
steps=[],
|
|
native_av_policy="native_av_v1",
|
|
)
|
|
if recipes
|
|
else None,
|
|
)
|