mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-22 07:10:28 +02:00
feat: Enhance text normalization and chunking logic to preserve original whitespace and handle abbreviations
This commit is contained in:
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
import re
|
||||
import unicodedata
|
||||
from dataclasses import dataclass
|
||||
from typing import List, Tuple, Iterable, Callable
|
||||
from typing import List, Tuple, Iterable, Callable, Optional
|
||||
|
||||
# ---------- Configuration Dataclass ----------
|
||||
|
||||
@@ -416,6 +416,26 @@ def apply_phoneme_hints(text: str, iz_marker="‹IZ›") -> str:
|
||||
"""
|
||||
return text.replace(iz_marker, " iz")
|
||||
|
||||
|
||||
DEFAULT_APOSTROPHE_CONFIG = ApostropheConfig()
|
||||
|
||||
|
||||
def normalize_for_pipeline(text: str, *, config: Optional[ApostropheConfig] = None) -> str:
|
||||
"""Normalize text for the synthesis pipeline.
|
||||
|
||||
This expands contractions, normalizes apostrophes, and adds phoneme hints
|
||||
using the provided configuration so downstream chunking and synthesis share
|
||||
the same representation.
|
||||
"""
|
||||
|
||||
cfg = config or DEFAULT_APOSTROPHE_CONFIG
|
||||
normalized, _details = normalize_apostrophes(text, cfg)
|
||||
normalized = expand_titles_and_suffixes(normalized)
|
||||
normalized = ensure_terminal_punctuation(normalized)
|
||||
if cfg.add_phoneme_hints:
|
||||
normalized = apply_phoneme_hints(normalized, iz_marker=cfg.sibilant_iz_marker)
|
||||
return normalized
|
||||
|
||||
# ---------- Example Usage ----------
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user