notmax123 commited on
Commit
ff5e826
·
1 Parent(s): 07b30a1

Add phonemes_for_display and strip language tags for user-facing text

Browse files
Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -146,6 +146,11 @@ def _strip_synthesis_tags(text: str) -> str:
146
  return _LANG_TAG_RE.sub(" ", text)
147
 
148
 
 
 
 
 
 
149
  def strip_hebrew_nikud(text: str) -> str:
150
  """Remove Hebrew niqqud/cantillation marks while preserving Hebrew letters."""
151
  return _HEBREW_NIKUD_RE.sub("", text)
@@ -1009,6 +1014,13 @@ def synthesize_text(text: str, voice: str, lang: str, steps: int, speed: float,
1009
  return (sr, wav), stats
1010
 
1011
 
 
 
 
 
 
 
 
1012
  # ============================================================
1013
  # Voice-clone tab
1014
  # ============================================================
 
146
  return _LANG_TAG_RE.sub(" ", text)
147
 
148
 
149
+ def strip_language_tags_for_display(text: str) -> str:
150
+ """Remove internal language tags from phoneme text shown to users."""
151
+ return re.sub(r"\s+", " ", _LANG_TAG_RE.sub("", text)).strip()
152
+
153
+
154
  def strip_hebrew_nikud(text: str) -> str:
155
  """Remove Hebrew niqqud/cantillation marks while preserving Hebrew letters."""
156
  return _HEBREW_NIKUD_RE.sub("", text)
 
1014
  return (sr, wav), stats
1015
 
1016
 
1017
+ def phonemes_for_display(text: str, lang: str) -> str:
1018
+ """Return user-facing phonemes without internal <lang> routing tags."""
1019
+ prepared = prepare_text_for_synthesis(text, lang=lang)
1020
+ tagged = TTS.g2p.phonemize(prepared, lang=lang)
1021
+ return strip_language_tags_for_display(tagged)
1022
+
1023
+
1024
  # ============================================================
1025
  # Voice-clone tab
1026
  # ============================================================