mirror of
https://github.com/denizsafak/abogen.git
synced 2026-09-20 19:50:59 +02:00
refactor: extract synthesize_text() domain function (#2)
Combines TTSContext.normalize() + run_tts_segment_loop() into a single domain function. Both UIs call synthesize_text() instead of inlining normalize → TTS loop. UI-specific concerns (provider resolution, progress display, cancellation) stay in the UI layer. Tests: 1253 passed
This commit is contained in:
+20
-22
@@ -36,7 +36,7 @@ from abogen.domain.output_paths import (
|
||||
)
|
||||
from abogen.domain.audio_helpers import build_ffmpeg_command, to_float32
|
||||
from abogen.domain.audio_sink import AudioSink, open_audio_sink
|
||||
from abogen.domain.conversion_engine import run_tts_segment_loop, SegmentStats, SegmentInfo
|
||||
from abogen.domain.conversion_engine import synthesize_text, SegmentStats, SegmentInfo
|
||||
from abogen.domain.intro_outro import resolve_intro, resolve_outro
|
||||
from abogen.domain.audio_buffer import (
|
||||
create_silence,
|
||||
@@ -982,14 +982,6 @@ class ConversionThread(QThread):
|
||||
print("Using split pattern: (unprintable)")
|
||||
|
||||
for text_segment in text_segments:
|
||||
# Normalize text before TTS
|
||||
try:
|
||||
text_segment = self._tts_context.normalize(text_segment)
|
||||
except Exception as exc:
|
||||
self.log_updated.emit(
|
||||
(f"Warning: Text normalization failed: {exc}", "orange")
|
||||
)
|
||||
|
||||
def _qt_check_cancel() -> bool:
|
||||
if self.cancel_requested:
|
||||
sink_stack.close()
|
||||
@@ -1049,19 +1041,25 @@ class ConversionThread(QThread):
|
||||
total_characters=self.total_char_count,
|
||||
)
|
||||
|
||||
run_tts_segment_loop(
|
||||
text=text_segment,
|
||||
backend=self.backend,
|
||||
voice=loaded_voice,
|
||||
speed=self.speed,
|
||||
split_pattern=active_split_pattern,
|
||||
stats=stats,
|
||||
check_cancel=_qt_check_cancel,
|
||||
on_progress=_qt_on_progress,
|
||||
chapter_sink=chapter_sink,
|
||||
audio_sink=merged_sink if merge_chapters_at_end else None,
|
||||
on_segment=_qt_on_segment,
|
||||
)
|
||||
try:
|
||||
synthesize_text(
|
||||
text=text_segment,
|
||||
tts_context=self._tts_context,
|
||||
backend=self.backend,
|
||||
voice=loaded_voice,
|
||||
speed=self.speed,
|
||||
stats=stats,
|
||||
check_cancel=_qt_check_cancel,
|
||||
on_progress=_qt_on_progress,
|
||||
chapter_sink=chapter_sink,
|
||||
audio_sink=merged_sink if merge_chapters_at_end else None,
|
||||
on_segment=_qt_on_segment,
|
||||
split_pattern_override=active_split_pattern,
|
||||
)
|
||||
except Exception as exc:
|
||||
self.log_updated.emit(
|
||||
(f"Warning: TTS failed: {exc}", "orange")
|
||||
)
|
||||
|
||||
self.processed_char_count = stats.processed_chars
|
||||
current_time = stats.current_time
|
||||
|
||||
Reference in New Issue
Block a user