mirror of
https://github.com/denizsafak/abogen.git
synced 2026-09-20 11:40:57 +02:00
refactor: SynthParams dataclass for synthesize_text
- Frozen dataclass in domain/conversion_engine.py with common params - synthesize_text now takes params=SynthParams + unique kwargs - Executor, PyQt legacy, WebUI legacy, and tests updated - Adding new common params now only requires changing the dataclass
This commit is contained in:
@@ -16,6 +16,7 @@ from typing import Any
|
||||
|
||||
from abogen.domain.conversion_engine import (
|
||||
synthesize_text,
|
||||
SynthParams,
|
||||
run_tts_segment_loop,
|
||||
process_and_write_subtitles,
|
||||
SegmentStats,
|
||||
@@ -133,18 +134,22 @@ class TestSynthesizeText:
|
||||
def on_progress(pct, etr):
|
||||
progress_calls.append((pct, etr))
|
||||
|
||||
segments, tokens = synthesize_text(
|
||||
text="Hello world.",
|
||||
params = SynthParams(
|
||||
tts_context=tts_ctx,
|
||||
backend=backend,
|
||||
voice="M1",
|
||||
speed=1.0,
|
||||
stats=stats,
|
||||
check_cancel=cancel,
|
||||
on_progress=on_progress,
|
||||
audio_sink=sink,
|
||||
)
|
||||
|
||||
segments, tokens = synthesize_text(
|
||||
text="Hello world.",
|
||||
params=params,
|
||||
backend=backend,
|
||||
voice="M1",
|
||||
speed=1.0,
|
||||
)
|
||||
|
||||
assert segments >= 1
|
||||
assert len(sink.written) >= 1
|
||||
assert len(progress_calls) >= 1
|
||||
@@ -159,17 +164,21 @@ class TestSynthesizeText:
|
||||
def on_progress(pct, etr):
|
||||
progress_calls.append((pct, etr))
|
||||
|
||||
segments, tokens = synthesize_text(
|
||||
text="Hello world.",
|
||||
params = SynthParams(
|
||||
tts_context=tts_ctx,
|
||||
backend=backend,
|
||||
voice="M1",
|
||||
speed=1.0,
|
||||
stats=stats,
|
||||
check_cancel=cancel,
|
||||
on_progress=on_progress,
|
||||
)
|
||||
|
||||
segments, tokens = synthesize_text(
|
||||
text="Hello world.",
|
||||
params=params,
|
||||
backend=backend,
|
||||
voice="M1",
|
||||
speed=1.0,
|
||||
)
|
||||
|
||||
# Should stop early due to cancellation
|
||||
assert segments == 0
|
||||
|
||||
@@ -184,19 +193,23 @@ class TestSynthesizeText:
|
||||
def on_progress(pct, etr):
|
||||
pass
|
||||
|
||||
segments, tokens = synthesize_text(
|
||||
text="Hello world.",
|
||||
params = SynthParams(
|
||||
tts_context=tts_ctx,
|
||||
backend=backend,
|
||||
voice="M1",
|
||||
speed=1.0,
|
||||
stats=stats,
|
||||
check_cancel=cancel,
|
||||
on_progress=on_progress,
|
||||
chapter_sink=chapter_sink,
|
||||
audio_sink=merged_sink,
|
||||
)
|
||||
|
||||
segments, tokens = synthesize_text(
|
||||
text="Hello world.",
|
||||
params=params,
|
||||
backend=backend,
|
||||
voice="M1",
|
||||
speed=1.0,
|
||||
chapter_sink=chapter_sink,
|
||||
)
|
||||
|
||||
# Both sinks should receive audio
|
||||
assert len(chapter_sink.written) >= 1
|
||||
assert len(merged_sink.written) >= 1
|
||||
@@ -210,15 +223,19 @@ class TestSynthesizeText:
|
||||
def on_progress(pct, etr):
|
||||
pass
|
||||
|
||||
segments, tokens = synthesize_text(
|
||||
text="Hello world.",
|
||||
params = SynthParams(
|
||||
tts_context=tts_ctx,
|
||||
backend=backend,
|
||||
voice="M1",
|
||||
speed=1.0,
|
||||
stats=stats,
|
||||
check_cancel=cancel,
|
||||
on_progress=on_progress,
|
||||
)
|
||||
|
||||
segments, tokens = synthesize_text(
|
||||
text="Hello world.",
|
||||
params=params,
|
||||
backend=backend,
|
||||
voice="M1",
|
||||
speed=1.0,
|
||||
split_pattern_override=r"\n+",
|
||||
)
|
||||
|
||||
@@ -323,16 +340,11 @@ class TestFullPipeline:
|
||||
progress_calls.append((pct, etr))
|
||||
|
||||
# Simulate full pipeline: synthesize → subtitles → finalize
|
||||
segments, tokens = synthesize_text(
|
||||
text="This is a test sentence. Another sentence here.",
|
||||
params = SynthParams(
|
||||
tts_context=tts_ctx,
|
||||
backend=backend,
|
||||
voice="M1",
|
||||
speed=1.0,
|
||||
stats=stats,
|
||||
check_cancel=cancel,
|
||||
on_progress=on_progress,
|
||||
chapter_sink=chapter_sink,
|
||||
audio_sink=merged_sink,
|
||||
subtitle_mode="Sentence",
|
||||
max_subtitle_words=5,
|
||||
@@ -340,6 +352,15 @@ class TestFullPipeline:
|
||||
use_spacy_segmentation=False,
|
||||
)
|
||||
|
||||
segments, tokens = synthesize_text(
|
||||
text="This is a test sentence. Another sentence here.",
|
||||
params=params,
|
||||
backend=backend,
|
||||
voice="M1",
|
||||
speed=1.0,
|
||||
chapter_sink=chapter_sink,
|
||||
)
|
||||
|
||||
# Process accumulated tokens
|
||||
process_and_write_subtitles(
|
||||
tokens,
|
||||
@@ -373,16 +394,20 @@ class TestFullPipeline:
|
||||
def on_progress(pct, etr):
|
||||
progress_calls.append((pct, etr))
|
||||
|
||||
segments, tokens = synthesize_text(
|
||||
text="Hello world. " * 100,
|
||||
params = SynthParams(
|
||||
tts_context=tts_ctx,
|
||||
backend=backend,
|
||||
voice="M1",
|
||||
speed=1.0,
|
||||
stats=stats,
|
||||
check_cancel=cancel_fn,
|
||||
on_progress=on_progress,
|
||||
)
|
||||
|
||||
segments, tokens = synthesize_text(
|
||||
text="Hello world. " * 100,
|
||||
params=params,
|
||||
backend=backend,
|
||||
voice="M1",
|
||||
speed=1.0,
|
||||
)
|
||||
|
||||
# Should have stopped before processing all text
|
||||
assert segments <= 4
|
||||
|
||||
Reference in New Issue
Block a user