Spaces:
Running
Running
Update utils.py
Browse files
utils.py
CHANGED
@@ -490,7 +490,7 @@ def _preprocess_text_for_tts(text: str, speaker: str) -> str:
|
|
490 |
"""
|
491 |
1) "SaaS" => "sass"
|
492 |
2) Insert periods for uppercase abbreviations -> remove for TTS
|
493 |
-
3)
|
494 |
4) Expand leftover all-caps
|
495 |
5) Emotive placeholders for 'ha', 'haha', 'sigh', 'groan', etc.
|
496 |
6) If speaker != Jane, insert filler words
|
@@ -512,17 +512,18 @@ def _preprocess_text_for_tts(text: str, speaker: str) -> str:
|
|
512 |
return chunk.replace(".", " ").strip()
|
513 |
text = re.sub(r"[A-Z0-9]\.[A-Z0-9](?:\.[A-Z0-9])*\.", remove_periods_for_tts, text)
|
514 |
|
515 |
-
# 3)
|
516 |
-
|
517 |
|
518 |
-
#
|
|
|
519 |
|
520 |
-
#
|
521 |
text = re.sub(r"\b(ha(ha)?|heh|lol)\b", "(* laughs *)", text, flags=re.IGNORECASE)
|
522 |
text = re.sub(r"\bsigh\b", "(* sighs *)", text, flags=re.IGNORECASE)
|
523 |
text = re.sub(r"\b(groan|moan)\b", "(* groans *)", text, flags=re.IGNORECASE)
|
524 |
|
525 |
-
#
|
526 |
if speaker != "Jane":
|
527 |
def insert_thinking_pause(m):
|
528 |
word = m.group(1)
|
@@ -537,10 +538,10 @@ def _preprocess_text_for_tts(text: str, speaker: str) -> str:
|
|
537 |
conj_pattern = r"\b(and|but|so|because|however)\b"
|
538 |
text = re.sub(conj_pattern, lambda m: f"{m.group()}...", text, flags=re.IGNORECASE)
|
539 |
|
540 |
-
#
|
541 |
text = re.sub(r"\b(uh|um|ah)\b", "", text, flags=re.IGNORECASE)
|
542 |
|
543 |
-
#
|
544 |
def capitalize_match(m):
|
545 |
return m.group().upper()
|
546 |
text = re.sub(r'(^\s*\w)|([.!?]\s*\w)', capitalize_match, text)
|
|
|
490 |
"""
|
491 |
1) "SaaS" => "sass"
|
492 |
2) Insert periods for uppercase abbreviations -> remove for TTS
|
493 |
+
3) Preserve numbers for natural TTS pronunciation
|
494 |
4) Expand leftover all-caps
|
495 |
5) Emotive placeholders for 'ha', 'haha', 'sigh', 'groan', etc.
|
496 |
6) If speaker != Jane, insert filler words
|
|
|
512 |
return chunk.replace(".", " ").strip()
|
513 |
text = re.sub(r"[A-Z0-9]\.[A-Z0-9](?:\.[A-Z0-9])*\.", remove_periods_for_tts, text)
|
514 |
|
515 |
+
# 3) Preserve numbers by removing any digit-specific processing
|
516 |
+
# Let TTS handle natural number pronunciation
|
517 |
|
518 |
+
# 4) Hyphens -> spaces (but preserve hyphenated numbers)
|
519 |
+
text = re.sub(r"(?<!\d)-(?!\d)", " ", text)
|
520 |
|
521 |
+
# 5) Emotive placeholders
|
522 |
text = re.sub(r"\b(ha(ha)?|heh|lol)\b", "(* laughs *)", text, flags=re.IGNORECASE)
|
523 |
text = re.sub(r"\bsigh\b", "(* sighs *)", text, flags=re.IGNORECASE)
|
524 |
text = re.sub(r"\b(groan|moan)\b", "(* groans *)", text, flags=re.IGNORECASE)
|
525 |
|
526 |
+
# 6) Insert filler words if speaker != "Jane"
|
527 |
if speaker != "Jane":
|
528 |
def insert_thinking_pause(m):
|
529 |
word = m.group(1)
|
|
|
538 |
conj_pattern = r"\b(and|but|so|because|however)\b"
|
539 |
text = re.sub(conj_pattern, lambda m: f"{m.group()}...", text, flags=re.IGNORECASE)
|
540 |
|
541 |
+
# 7) Remove random fillers
|
542 |
text = re.sub(r"\b(uh|um|ah)\b", "", text, flags=re.IGNORECASE)
|
543 |
|
544 |
+
# 8) Capitalize sentence starts
|
545 |
def capitalize_match(m):
|
546 |
return m.group().upper()
|
547 |
text = re.sub(r'(^\s*\w)|([.!?]\s*\w)', capitalize_match, text)
|