MCPcopy Create free account
hub / github.com/FireRedTeam/FireRedTTS / zh_text_split

Function zh_text_split

fireredtts/modules/text_normalizer/utils.py:132–155  ·  view source on GitHub ↗
(text, length=80)

Source from the content-addressed store, hash-verified

130
131
132def zh_text_split(text, length=80):
133 if length == 0:
134 return []
135 if length == 1:
136 return [c for c in length]
137 if len(text) <= length:
138 return [text]
139
140 match_strong = re.search(strong_break, text[:length][::-1])
141 match_weak = re.search(weak_break, text[:length][::-1])
142 end_ind_strong = length - match_strong.start() if match_strong else 0
143 end_ind_weak = length - match_weak.start() if match_weak else 0
144
145 if end_ind_strong < length // 3:
146 if end_ind_weak < length // 3:
147 valid_max = max(end_ind_strong, end_ind_weak)
148 if valid_max >= 3:
149 return [text[:valid_max]] + zh_text_split(text[valid_max:])
150 else:
151 return [text[:length]] + zh_text_split(text[length:])
152 else:
153 return [text[:end_ind_weak]] + zh_text_split(text[end_ind_weak:])
154 else:
155 return [text[:end_ind_strong]] + zh_text_split(text[end_ind_strong:])
156
157
158def text_split(text):

Callers 1

text_splitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected