extract normalize_text_for_pipeline to domain/normalization.py

This commit is contained in:
Artem Akymenko
2026-07-15 15:19:01 +00:00
parent 56cfd0810d
commit 7fef9c1d93
3 changed files with 36 additions and 20 deletions
+30
View File
@@ -0,0 +1,30 @@
"""Text normalization convenience helpers."""
from __future__ import annotations
from typing import Any, Mapping, Optional
from abogen.kokoro_text_normalization import (
ApostropheConfig,
normalize_for_pipeline as _normalize_for_pipeline,
)
from abogen.normalization_settings import (
build_apostrophe_config,
get_runtime_settings,
apply_overrides as _apply_overrides,
)
_BASE_APOSTROPHE_CONFIG = ApostropheConfig()
def normalize_text_for_pipeline(
text: str,
*,
normalization_overrides: Optional[Mapping[str, Any]] = None,
) -> str:
"""Normalize text using runtime settings with optional overrides."""
runtime_settings = get_runtime_settings()
if normalization_overrides:
runtime_settings = _apply_overrides(runtime_settings, normalization_overrides)
apostrophe_config = build_apostrophe_config(settings=runtime_settings, base=_BASE_APOSTROPHE_CONFIG)
return _normalize_for_pipeline(text, config=apostrophe_config, settings=runtime_settings)
-14
View File
@@ -139,20 +139,6 @@ class AudioSink:
_APOSTROPHE_CONFIG = ApostropheConfig()
def _normalize_for_pipeline(
text: str,
*,
normalization_overrides: Optional[Mapping[str, Any]] = None,
) -> str:
"""Normalize text for tests or utilities with optional overrides."""
runtime_settings = get_runtime_settings()
if normalization_overrides:
runtime_settings = apply_normalization_overrides(runtime_settings, normalization_overrides)
apostrophe_config = build_apostrophe_config(settings=runtime_settings, base=_APOSTROPHE_CONFIG)
return normalize_for_pipeline(text, config=apostrophe_config, settings=runtime_settings)
def _apply_m4b_chapters_with_mutagen(
audio_path: Path,
chapters: List[Dict[str, Any]],