walidadebayo commited on
Commit
9c4e2f2
·
1 Parent(s): b435288

Refactor punctuation handling in text_to_speech function for improved accuracy

Browse files
Files changed (1) hide show
  1. app.py +1 -18
app.py CHANGED
@@ -77,26 +77,9 @@ async def text_to_speech(text, voice, rate, pitch, generate_subtitles=False):
77
 
78
  current_phrase.append(boundary)
79
 
80
- # Improved punctuation handling for all cases
81
- if word in ['.', ',', '!', '?', ':', ';']:
82
- # Standalone punctuation
83
  current_text = current_text.rstrip() + word + " "
84
- elif word.startswith(('.', ',', '!', '?', ':', ';')) and word.endswith(('.', ',', '!', '?', ':', ';')):
85
- # Word with punctuation at both beginning and end (rare case)
86
- punctuation_start = word[0]
87
- punctuation_end = word[-1]
88
- remaining_word = word[1:-1]
89
- current_text = current_text.rstrip() + punctuation_start + " " + remaining_word + punctuation_end + " "
90
- elif word.startswith(('.', ',', '!', '?', ':', ';')):
91
- # Word with punctuation at beginning
92
- punctuation = word[0]
93
- remaining_word = word[1:]
94
- current_text = current_text.rstrip() + punctuation + " " + remaining_word + " "
95
- elif word.endswith(('.', ',', '!', '?', ':', ';')):
96
- # Word with punctuation at end (common case)
97
- current_text += word + " " # Keep punctuation attached to word
98
  else:
99
- # Regular word with no punctuation
100
  current_text += word + " "
101
 
102
  # Determine if we should end this phrase and start a new one
 
77
 
78
  current_phrase.append(boundary)
79
 
80
+ if word in ['.', ',', '!', '?', ':', ';'] or word.startswith(('.', ',', '!', '?', ':', ';')):
 
 
81
  current_text = current_text.rstrip() + word + " "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  else:
 
83
  current_text += word + " "
84
 
85
  # Determine if we should end this phrase and start a new one