"""H3 原生音视频使用独立实测证据,不能继承静音视频或后配口型认证。""" import re from app.domain import native_silence from app.domain.native_av import TURN_POLICY from app.domain.video_generation import ( H3_NATIVE_AV_PROFILE, H3_NATIVE_AV_TP2_PROFILE, H3_NATIVE_AV_PROFILES, ) TURN_CERTIFICATION_REASON = "同框轮读缺少独立的逐轮验收和冻结留出集认证,可编辑草稿及离线试验。" CERTIFICATION_REASON = "H3原生音视频尚未启用或尚未完成独立实测认证。" REVISION = "12253298adb81e36757eabebb81d2ba1c0cc70cc" RUNTIME_REVISION = "f53d552036a0d1bd5570782a39cd40cfabf112bc" TP2_RUNTIME_REVISION = "423ab90580b2847998591669b8326f47b6d14d8b" ALIGNMENT_REASON = "原生对白逐词识别尚未完成独立实测认证。" CANVASES = [[1344, 768], [768, 1344]] CANVAS_REASON = "当前原生画布尚未通过实测验收,请使用实时能力中已认证的画布。" def valid_canvases(value): return ( isinstance(value, list) and 1 <= len(value) <= len(CANVASES) and all( isinstance(c, list) and len(c) == 2 and all(type(v) is int for v in c) and c in CANVASES for c in value ) and value == [c for c in CANVASES if c in value] ) def enabled(settings, profile): if profile not in H3_NATIVE_AV_PROFILES: return False flag = ( "native_dialogue_tp2_enabled" if profile == H3_NATIVE_AV_TP2_PROFILE else "native_dialogue_enabled" ) return ( bool(getattr(settings, "inference_base_url", "")) and getattr(settings, flag, False) is True ) def select_evidence(snapshot, profile): if not isinstance(snapshot, dict) or profile not in H3_NATIVE_AV_PROFILES: return {} generation = snapshot.get("video_generation") if not isinstance(generation, dict): return {} key = "native_av_tp2" if profile == H3_NATIVE_AV_TP2_PROFILE else "native_av" value = generation.get(key) return value if isinstance(value, dict) else {} def certified(evidence, profile=H3_NATIVE_AV_PROFILE): if not isinstance(evidence, dict) or profile not in H3_NATIVE_AV_PROFILES: return False tp2 = profile == H3_NATIVE_AV_TP2_PROFILE integers = {"fps": 24, "audio_sample_rate": 32000, "audio_channels": 2} return ( evidence.get("available") is True and evidence.get("decision") == "pass" and evidence.get("audited") is True and evidence.get("profile") == profile and evidence.get("revision") == REVISION and evidence.get("runtime_revision") == (TP2_RUNTIME_REVISION if tp2 else RUNTIME_REVISION) and evidence.get("adapter_contract_version") == ("h3-fl2va-native-av-tp2-v1" if tp2 else "h3-fl2va-native-av-v1") and evidence.get("input_modes") == (["first_frame"] if tp2 else ["first_frame", "first_last_frame"]) and evidence.get("output_policy") == "full_native" and evidence.get("native_frame_counts") == list(range(124, 159 if tp2 else 346, 17)) and all(type(v) is int for v in evidence["native_frame_counts"]) and valid_canvases(evidence.get("canvases")) and all(type(evidence.get(k)) is int and evidence[k] == v for k, v in integers.items()) and evidence.get("audio_output") is True and evidence.get("upscale") is False and bool(re.fullmatch(r"[0-9a-f]{64}", str(evidence.get("report_sha256", "")))) ) def canvas_certified(evidence, profile, width, height): return ( certified(evidence, profile) and type(width) is int and type(height) is int and [width, height] in evidence["canvases"] ) async def available(provider, profile=H3_NATIVE_AV_PROFILE, *, canvas=None, settings=None): if not enabled(settings if settings is not None else provider.settings, profile): return False try: snapshot = await provider.upstream_capabilities() evidence = select_evidence(snapshot, profile) if canvas is not None: return ( isinstance(canvas, (list, tuple)) and len(canvas) == 2 and canvas_certified(evidence, profile, *canvas) ) return certified(evidence, profile) except Exception: return False def alignment_evidence(snapshot): dialogue = snapshot.get("dialogue") if isinstance(snapshot, dict) else None speech = dialogue.get("speech_inspect") if isinstance(dialogue, dict) else None result = speech.get("native_alignment") if isinstance(speech, dict) else None return result if isinstance(result, dict) else {} def alignment_certified(evidence): return ( isinstance(evidence, dict) and evidence.get("available") is True and evidence.get("decision") == "pass" and evidence.get("audited") is True and evidence.get("profile") == "dialogue-audio-v1" and evidence.get("revision") == "f0c48c298fd835726c27956a5d617bad7115627e" and evidence.get("asr_revision") == "41f01f3fe87f28c78e2fbf8b568835947dd65ed9" and evidence.get("content_verification_policy") == "whisper-sensevoice-consensus-v1" and evidence.get("secondary_asr_revision") == "90c1c61912018b70ada0fcc024ea24aca62f2e63" and evidence.get("secondary_runtime_revision") == "6991744856587fa44379e8b5dcc432debffeb1be" and evidence.get("silence_verification_policy") == native_silence.POLICY and evidence.get("silence_vad_revision") == native_silence.REVISION and evidence.get("silence_vad_sha256") == native_silence.MODEL_SHA256 and evidence.get("policy") == "native_av_v1" and evidence.get("timestamp_source") == "whisper-word-timestamps" and type(evidence.get("sample_rate")) is int and evidence["sample_rate"] == 48000 and bool(re.fullmatch(r"[0-9a-f]{64}", str(evidence.get("report_sha256", "")))) ) def alignment_enabled(settings, snapshot): return any(enabled(settings, p) for p in H3_NATIVE_AV_PROFILES) and alignment_certified( alignment_evidence(snapshot) ) async def alignment_available(provider): if not any(enabled(provider.settings, p) for p in H3_NATIVE_AV_PROFILES): return False try: return alignment_enabled(provider.settings, await provider.upstream_capabilities()) except Exception: return False TURN_SOURCES = ( "video", "native_audio", "speech_audio", "speech_report", "first_frame", "visual_review", "face_0", "face_1", "voice_0", "voice_1", ) def turn_evidence(snapshot): dialogue = snapshot.get("dialogue", {}) if isinstance(snapshot, dict) else {} evidence = dialogue.get("two_person_turns") if isinstance(dialogue, dict) else None return evidence if isinstance(evidence, dict) else {} def turn_certificate(snapshot, parameters): ev = turn_evidence(snapshot) profile = parameters.get("profile") tp2 = profile == H3_NATIVE_AV_TP2_PROFILE if ( profile in H3_NATIVE_AV_PROFILES and ev.get("available") is True and ev.get("audited") is True and ev.get("decision") == "pass" and ev.get("policy") == TURN_POLICY and ev.get("release_policy") == "h3-two-person-turns-release-v1" and ev.get("revision") == REVISION and ev.get("runtime_revision") == (TP2_RUNTIME_REVISION if tp2 else RUNTIME_REVISION) and ev.get("profile") == profile and ev.get("fps") == 24 and ev.get("language") == "Chinese" and [ev.get("width"), ev.get("height")] == [parameters.get("width"), parameters.get("height")] == [1344, 768] and ev.get("num_frames") == parameters.get("num_frames") and ev.get("num_frames") in range(124, 159 if tp2 else 346, 17) and ev.get("tasks") == 24 and type(ev.get("first_pass")) is int and type(ev.get("overall_pass")) is int and 18 <= ev["first_pass"] <= ev["overall_pass"] <= 24 and ev["overall_pass"] >= 22 and re.fullmatch("[0-9a-f]{64}", str(ev.get("report_sha256", ""))) ): return ev["report_sha256"] return None