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_helpers import build_ffmpeg_command, to_float32
|
||||||
from abogen.domain.audio_sink import AudioSink, open_audio_sink
|
from abogen.domain.audio_sink import AudioSink, open_audio_sink
|
||||||
|
from abogen.domain.tokens import FakeToken
|
||||||
from abogen.domain.audio_buffer import (
|
from abogen.domain.audio_buffer import (
|
||||||
create_silence,
|
create_silence,
|
||||||
mix_audio,
|
mix_audio,
|
||||||
@@ -1086,14 +1087,6 @@ class ConversionThread(QThread):
|
|||||||
# Fallback for languages without token support (non-English)
|
# Fallback for languages without token support (non-English)
|
||||||
# Create a single token representing the entire segment duration
|
# Create a single token representing the entire segment duration
|
||||||
if not tokens_list and result.graphemes:
|
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 = [
|
tokens_list = [
|
||||||
FakeToken(result.graphemes, 0, chunk_dur)
|
FakeToken(result.graphemes, 0, chunk_dur)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ from abogen.domain.audio_buffer import (
|
|||||||
SAMPLE_RATE,
|
SAMPLE_RATE,
|
||||||
)
|
)
|
||||||
from abogen.domain.audio_sink import AudioSink, open_audio_sink
|
from abogen.domain.audio_sink import AudioSink, open_audio_sink
|
||||||
|
from abogen.domain.tokens import FakeToken
|
||||||
|
|
||||||
|
|
||||||
from .service import Job, JobStatus
|
from .service import Job, JobStatus
|
||||||
@@ -132,16 +133,6 @@ SPLIT_PATTERN = r"\n+" # Kept for backward compatibility; prefer get_split_patt
|
|||||||
SAMPLE_RATE = 24000
|
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):
|
class _JobCancelled(Exception):
|
||||||
"""Raised internally to abort a conversion when the client cancels."""
|
"""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
|
# Fallback for languages without token support: create a single token
|
||||||
if not tokens_list and graphemes:
|
if not tokens_list and graphemes:
|
||||||
tokens_list = [_FakeToken(graphemes, 0, duration)]
|
tokens_list = [FakeToken(graphemes, 0, duration)]
|
||||||
|
|
||||||
for tok in tokens_list:
|
for tok in tokens_list:
|
||||||
accumulated_tokens.append({
|
accumulated_tokens.append({
|
||||||
|
|||||||
Reference in New Issue
Block a user