fix(audio): detect transcript-wide hallucinations

This commit is contained in:
2026-08-12 13:32:10 +08:00
parent c321d020dd
commit 48f4efaf3d
10 changed files with 318 additions and 13 deletions
+27
View File
@@ -3,6 +3,7 @@ from __future__ import annotations
from types import SimpleNamespace
from imagefind.speech_quality import (
aggregate_transcript_quality,
normalize_language,
pcm16_voiced_regions,
select_language,
@@ -10,6 +11,32 @@ from imagefind.speech_quality import (
)
def test_aggregate_quality_rejects_repeated_short_hallucinations() -> None:
segments = ([{"text": ""}] * 11) + ([{"text": "拜拜"}] * 7) + ([{"text": "正常对话内容"}] * 4)
result = aggregate_transcript_quality(segments, base_score=1.0)
assert result.score < 0.7
assert "whole_repeated_phrase" in result.flags
assert "whole_short_segment_dominance" in result.flags
assert "whole_ending_hallucination" in result.flags
assert ("拜拜", 7) in result.repeated_phrases
def test_sports_samples_patterns_cannot_remain_ready() -> None:
sports_2 = ([{"text": ""}] * 11) + ([{"text": "拜拜"}] * 7) + ([{"text": ""}] * 5)
sports_2 += [{"text": f"正常对话{i}"} for i in range(19)]
sports_3 = ([{"text": "拜拜"}] * 8) + ([{"text": ""}] * 7) + ([{"text": ""}] * 7)
sports_3 += ([{"text": "谢谢大家收看"}] * 3) + [{"text": f"正常内容{i}"} for i in range(32)]
for segments in (sports_2, sports_3):
result = aggregate_transcript_quality(segments, base_score=1.0)
assert result.score < 0.7
assert "whole_repeated_phrase" in result.flags
def test_traditional_ending_phrase_is_flagged() -> None:
result = aggregate_transcript_quality([{"text": "謝謝大家收看"}] * 3, base_score=1.0)
assert "whole_ending_hallucination" in result.flags
def test_language_policy_treats_stream_metadata_as_weak_hint() -> None:
assert select_language(["en", "zh"], policy="zh_priority") == "zh"
assert select_language(["en", "zh"], policy="auto") == "en"