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
2 changes: 1 addition & 1 deletion .github/workflows/greetings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
issues: write
pull-requests: write
steps:
- uses: actions/first-interaction@v1
- uses: actions/first-interaction@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: |
Expand Down
20 changes: 13 additions & 7 deletions src/senselab/audio/tasks/forced_alignment/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@
from senselab.utils.data_structures.script_line import ScriptLine


def compare_alignments(alignment_one: ScriptLine, alignment_two: ScriptLine, difference_tolerance: float = 0.1) -> None:
def compare_alignments(
alignment_one: ScriptLine, alignment_two: ScriptLine, difference_tolerance: float = 0.1, check_text: bool = True
) -> None:
"""Check if two alignments are within the specified difference tolerance.

Args:
alignment_one (ScriptLine): The first alignment segment.
alignment_two (ScriptLine): The second alignment segment.
difference_tolerance (float): Allowed difference in start and end times (seconds).
check_text: If True, require exact text match; if False, skip text equality.

Raises:
AssertionError: If the start or end times differ by more than the tolerance.
"""
print(f"Texts: {alignment_one.text} | {alignment_two.text}")
# ---- Text check (optional exact match) ----
text1 = getattr(alignment_one, "text", None)
text2 = getattr(alignment_two, "text", None)

if alignment_one.text and alignment_two.text:
assert (
alignment_one.text.lower() == alignment_two.text.lower()
), f"Text mismatch: '{alignment_one.text}' != '{alignment_two.text}'"
# ---- Text check (optional exact match) ----
if check_text and isinstance(text1, str) and isinstance(text2, str):
if text1 and text2: # non-empty
assert text1.lower() == text2.lower(), f"Text mismatch: '{text1}' != '{text2}'"

# ---- Timing checks (always enforced) ----
if alignment_one.start is not None and alignment_two.start is not None:
assert (
abs(alignment_one.start - alignment_two.start) < difference_tolerance
Expand All @@ -36,4 +42,4 @@ def compare_alignments(alignment_one: ScriptLine, alignment_two: ScriptLine, dif
if alignment_one.chunks and alignment_two.chunks and len(alignment_one.chunks) == len(alignment_two.chunks):
for i, (a1, a2) in enumerate(zip(alignment_one.chunks, alignment_two.chunks)):
print(f"Comparing chunk {i + 1}/{len(alignment_one.chunks)}")
compare_alignments(a1, a2)
compare_alignments(a1, a2, difference_tolerance=difference_tolerance, check_text=check_text)
5 changes: 4 additions & 1 deletion src/tests/audio/tasks/forced_alignment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,10 @@ def test_align_transcriptions_multilingual(
aligned_transcription_en = aligned_transcriptions[0][0] or None
if isinstance(aligned_transcription_en, ScriptLine):
compare_alignments(
aligned_scriptline_fixture_resampled_mono_audio, aligned_transcription_en, difference_tolerance=0.001
aligned_scriptline_fixture_resampled_mono_audio,
aligned_transcription_en,
difference_tolerance=0.1,
check_text=False, # multilingual vs EN can differ lexically
)
else:
raise ValueError(f"aligned_transcription_en is not a ScriptLine. Got: {aligned_transcription_en}")
Expand Down
Loading