siddhartharyaai commited on
Commit
cabe6ff
·
verified ·
1 Parent(s): 24d0657

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +5 -1
utils.py CHANGED
@@ -16,6 +16,7 @@ from groq import Groq
16
  import numpy as np
17
  import torch
18
  import random
 
19
 
20
  class DialogueItem(BaseModel):
21
  speaker: Literal["Jane", "John"] # TTS voice
@@ -534,7 +535,10 @@ def _preprocess_text_for_tts(text: str, speaker: str) -> str:
534
  # 5) Convert pure integer => words
535
  def convert_int_to_words(m):
536
  num_str = m.group()
537
- return number_to_words(int(num_str))
 
 
 
538
  # Updated regex to catch all digit sequences
539
  text = re.sub(r"\d+", convert_int_to_words, text)
540
 
 
16
  import numpy as np
17
  import torch
18
  import random
19
+ from num2words import num2words # Added for robust number-to-words conversion
20
 
21
  class DialogueItem(BaseModel):
22
  speaker: Literal["Jane", "John"] # TTS voice
 
535
  # 5) Convert pure integer => words
536
  def convert_int_to_words(m):
537
  num_str = m.group()
538
+ try:
539
+ return num2words(int(num_str))
540
+ except Exception:
541
+ return num_str
542
  # Updated regex to catch all digit sequences
543
  text = re.sub(r"\d+", convert_int_to_words, text)
544