"""Voice worker: sentence splitting for streaming TTS, whole and incremental.""" from __future__ import annotations import pytest from voice_worker.sentences import StreamingSplitter, split_sentences @pytest.mark.unit def test_splits_on_terminal_punctuation_only(): assert split_sentences("안녕하세요. 오늘은 맑아요! 우산은 필요 없어요?") == [ "안녕하세요.", "오늘은 맑아요!", "우산은 필요 없어요?"] @pytest.mark.unit def test_decimals_versions_and_urls_stay_whole(): assert split_sentences("기온은 17.5도예요. 자세한 건 example.com 에 있어요.") == [ "기온은 17.5도예요.", "자세한 건 example.com 에 있어요."] @pytest.mark.unit def test_cjk_terminators_split_without_spaces(): assert split_sentences("今日は晴れです。明日は雨です。") == ["今日は晴れです。", "明日は雨です。"] @pytest.mark.unit def test_short_fragments_merge_into_a_neighbour(): assert split_sentences("네. 알람을 일곱 시에 맞췄어요.") == ["네. 알람을 일곱 시에 맞췄어요."] @pytest.mark.unit def test_streaming_holds_the_unfinished_tail_until_more_text_arrives(): s = StreamingSplitter() assert s.feed("오늘 서울은 맑") == [] assert s.feed("아요. 기온은 17") == ["오늘 서울은 맑아요."] assert s.feed(".5도예요. 바람은") == ["기온은 17.5도예요."] assert s.finish() == ["바람은"] @pytest.mark.unit def test_streaming_output_equals_whole_text_split(): text = "첫 문장입니다. 두 번째 문장이에요! 세 번째는 질문인가요? 마지막 문장이에요." s = StreamingSplitter() got = [] for i in range(0, len(text), 3): got += s.feed(text[i:i + 3]) got += s.finish() assert got == split_sentences(text)