Skip to content
Draft
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
33 changes: 32 additions & 1 deletion tests/test_audio_ocr_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from types import SimpleNamespace

from llm_workflows.audio_text import (
convert_time_to_srt_format, create_multiline_srt, split_line_by_char_limit,
convert_time_to_srt_format, create_multiline_srt, format_segments, split_line_by_char_limit,
)
from utils.full_multi_updated2 import detect_languages_in_text, save_results

Expand All @@ -22,6 +24,35 @@ def test_multiline_srt_file(tmp_path):
assert out.read_text(encoding="utf-8") == "1\n00:00:00,000 --> 00:00:01,250\nhello world\nagain\n\n"


def test_format_segments_handles_empty_and_optional_word_timestamps():
assert format_segments([]) == ([], [], "")

segments = [
SimpleNamespace(text=" first sentence ", start=0.0, end=1.2),
SimpleNamespace(
text=" second sentence ",
start=1.2,
end=2.5,
words=[
SimpleNamespace(word=" first ", start=1.2, end=1.5),
SimpleNamespace(word=" second ", start=1.6, end=2.0),
],
),
]

sentences, words, transcript = format_segments(segments)

assert sentences == [
{"id": 0, "text": "first sentence", "start": 0.0, "end": 1.2},
{"id": 1, "text": "second sentence", "start": 1.2, "end": 2.5},
]
assert words == [
{"word": "first", "start": 1.2, "end": 1.5},
{"word": "second", "start": 1.6, "end": 2.0},
]
assert transcript == "first sentence second sentence"


def test_detect_languages():
assert detect_languages_in_text("hello") == ["Latin_Script"]
assert detect_languages_in_text("ଓଡ଼ିଆ") == ["Odia"]
Expand Down