siddhartharyaai commited on
Commit
43b0279
·
verified ·
1 Parent(s): af5ec3e

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +9 -8
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) Convert decimals like "3.14" -> "three point one four"
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) Hyphens -> spaces
516
- text = re.sub(r"-", " ", text)
517
 
518
- # Removed numeric conversions to let TTS handle numbers naturally.
 
519
 
520
- # 6) Emotive placeholders
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
- # 7) Insert filler words if speaker != "Jane"
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
- # 8) Remove random fillers
541
  text = re.sub(r"\b(uh|um|ah)\b", "", text, flags=re.IGNORECASE)
542
 
543
- # 9) Capitalize sentence starts
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)