Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/docgen/narration_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ def lint_pre_tts(text: str, deny_patterns: list[str] | None = None) -> LintResul
return LintResult(stage="pre-tts", passed=len(issues) == 0, issues=issues)


def _empty_transcript_issues(transcript: str) -> list[str]:
"""An empty Whisper transcript has no speech for the artifact scan to clear."""
if transcript.strip():
return []
return [
"Whisper transcript is empty — post-tts lint cannot pass audio with no spoken words"
]


def lint_post_tts(transcript: str, deny_patterns: list[str] | None = None) -> LintResult:
"""Scan Whisper transcript of generated audio for spoken artifacts."""
patterns = deny_patterns or [
Expand All @@ -75,7 +84,7 @@ def lint_post_tts(transcript: str, deny_patterns: list[str] | None = None) -> Li
"backtick",
]

issues: list[str] = []
issues = _empty_transcript_issues(transcript)
lower = transcript.lower()
for pat in patterns:
if re.search(pat, lower, re.IGNORECASE):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_narration_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,15 @@ def test_post_tts_script_section():
def test_post_tts_custom_patterns():
result = lint_post_tts("Normal speech here.", deny_patterns=["normal speech"])
assert not result.passed


def test_post_tts_empty_transcript_fails():
result = lint_post_tts("")
assert not result.passed
assert any("empty" in i.lower() for i in result.issues)


def test_post_tts_whitespace_transcript_fails():
result = lint_post_tts(" \n\t ")
assert not result.passed
assert any("empty" in i.lower() for i in result.issues)
Loading