- One shared faster-whisper model for every speaker, batched; finals go before partials and partial batches are capped at two so a final never waits behind a ten-speaker pass. - Per-speaker 48k stereo to 16k mono conversion, streaming Silero VAD, utterance ends on VAD silence, Discord speaking_end, missing audio, or the 28 s Whisper window. - MeloTTS in its own venv through a child process; sentences stream out one chunk each, with incremental text, cancel and failure reporting. - Loopback-only server with a token from the environment; logs carry no transcript text. - Spec in src/voice_worker/voice_worker.spec.md; unit tests with fake engines and an opt-in real-GPU test that streams ten speakers at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
"""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)
|
|
|