mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
refactor(domain): extract FakeToken to domain/tokens.py
Shared token stub used by both WebUI and PyQt for languages without per-word token support.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
"""Shared token stubs for TTS processing."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
class FakeToken:
|
||||
"""Minimal token stub for languages without per-word token support."""
|
||||
|
||||
def __init__(self, text: str, start: float, end: float):
|
||||
self.text = text
|
||||
self.start_ts = start
|
||||
self.end_ts = end
|
||||
self.whitespace = ""
|
||||
@@ -31,6 +31,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.tokens import FakeToken
|
||||
from abogen.domain.audio_buffer import (
|
||||
create_silence,
|
||||
mix_audio,
|
||||
@@ -1086,14 +1087,6 @@ class ConversionThread(QThread):
|
||||
# Fallback for languages without token support (non-English)
|
||||
# Create a single token representing the entire segment duration
|
||||
if not tokens_list and result.graphemes:
|
||||
|
||||
class FakeToken:
|
||||
def __init__(self, text, start, end):
|
||||
self.text = text
|
||||
self.start_ts = start
|
||||
self.end_ts = end
|
||||
self.whitespace = ""
|
||||
|
||||
tokens_list = [
|
||||
FakeToken(result.graphemes, 0, chunk_dur)
|
||||
]
|
||||
|
||||
@@ -121,6 +121,7 @@ from abogen.domain.audio_buffer import (
|
||||
SAMPLE_RATE,
|
||||
)
|
||||
from abogen.domain.audio_sink import AudioSink, open_audio_sink
|
||||
from abogen.domain.tokens import FakeToken
|
||||
|
||||
|
||||
from .service import Job, JobStatus
|
||||
@@ -132,16 +133,6 @@ SPLIT_PATTERN = r"\n+" # Kept for backward compatibility; prefer get_split_patt
|
||||
SAMPLE_RATE = 24000
|
||||
|
||||
|
||||
class _FakeToken:
|
||||
"""Minimal token stub for languages without per-word token support."""
|
||||
|
||||
def __init__(self, text: str, start: float, end: float):
|
||||
self.text = text
|
||||
self.start_ts = start
|
||||
self.end_ts = end
|
||||
self.whitespace = ""
|
||||
|
||||
|
||||
class _JobCancelled(Exception):
|
||||
"""Raised internally to abort a conversion when the client cancels."""
|
||||
|
||||
@@ -543,7 +534,7 @@ def run_conversion_job(job: Job) -> None:
|
||||
|
||||
# Fallback for languages without token support: create a single token
|
||||
if not tokens_list and graphemes:
|
||||
tokens_list = [_FakeToken(graphemes, 0, duration)]
|
||||
tokens_list = [FakeToken(graphemes, 0, duration)]
|
||||
|
||||
for tok in tokens_list:
|
||||
accumulated_tokens.append({
|
||||
|
||||
Reference in New Issue
Block a user