Spaces:
Running
on
Zero
Running
on
Zero
mrfakename
commited on
Sync from GitHub repo
Browse filesThis Space is synced from the GitHub repo: https://github.com/SWivid/F5-TTS. Please submit contributions to the Space there
- src/f5_tts/infer/utils_infer.py +2 -1
- src/f5_tts/model/utils.py +22 -16
src/f5_tts/infer/utils_infer.py
CHANGED
@@ -346,7 +346,7 @@ def preprocess_ref_audio_text(ref_audio_orig, ref_text, clip_short=True, show_in
|
|
346 |
else:
|
347 |
ref_text += ". "
|
348 |
|
349 |
-
print("
|
350 |
|
351 |
return ref_audio, ref_text
|
352 |
|
@@ -378,6 +378,7 @@ def infer_process(
|
|
378 |
gen_text_batches = chunk_text(gen_text, max_chars=max_chars)
|
379 |
for i, gen_text in enumerate(gen_text_batches):
|
380 |
print(f"gen_text {i}", gen_text)
|
|
|
381 |
|
382 |
show_info(f"Generating audio in {len(gen_text_batches)} batches...")
|
383 |
return infer_batch_process(
|
|
|
346 |
else:
|
347 |
ref_text += ". "
|
348 |
|
349 |
+
print("\nref_text ", ref_text)
|
350 |
|
351 |
return ref_audio, ref_text
|
352 |
|
|
|
378 |
gen_text_batches = chunk_text(gen_text, max_chars=max_chars)
|
379 |
for i, gen_text in enumerate(gen_text_batches):
|
380 |
print(f"gen_text {i}", gen_text)
|
381 |
+
print("\n")
|
382 |
|
383 |
show_info(f"Generating audio in {len(gen_text_batches)} batches...")
|
384 |
return infer_batch_process(
|
src/f5_tts/model/utils.py
CHANGED
@@ -133,16 +133,23 @@ def get_tokenizer(dataset_name, tokenizer: str = "pinyin"):
|
|
133 |
|
134 |
# convert char to pinyin
|
135 |
|
|
|
|
|
|
|
136 |
|
137 |
def convert_char_to_pinyin(text_list, polyphone=True):
|
138 |
final_text_list = []
|
139 |
-
|
140 |
-
{"β": '"', "β": '"', "β": "'", "β": "'"}
|
141 |
-
) #
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
143 |
for text in text_list:
|
144 |
char_list = []
|
145 |
-
text = text.translate(god_knows_why_en_testset_contains_zh_quote)
|
146 |
text = text.translate(custom_trans)
|
147 |
for seg in jieba.cut(text):
|
148 |
seg_byte_len = len(bytes(seg, "UTF-8"))
|
@@ -150,22 +157,21 @@ def convert_char_to_pinyin(text_list, polyphone=True):
|
|
150 |
if char_list and seg_byte_len > 1 and char_list[-1] not in " :'\"":
|
151 |
char_list.append(" ")
|
152 |
char_list.extend(seg)
|
153 |
-
elif polyphone and seg_byte_len == 3 * len(seg): # if pure
|
154 |
-
|
155 |
-
for c in seg:
|
156 |
-
if c
|
157 |
char_list.append(" ")
|
158 |
-
char_list.append(
|
159 |
-
else: # if mixed
|
160 |
for c in seg:
|
161 |
if ord(c) < 256:
|
162 |
char_list.extend(c)
|
|
|
|
|
|
|
163 |
else:
|
164 |
-
|
165 |
-
char_list.append(" ")
|
166 |
-
char_list.extend(lazy_pinyin(c, style=Style.TONE3, tone_sandhi=True))
|
167 |
-
else: # if is zh punc
|
168 |
-
char_list.append(c)
|
169 |
final_text_list.append(char_list)
|
170 |
|
171 |
return final_text_list
|
|
|
133 |
|
134 |
# convert char to pinyin
|
135 |
|
136 |
+
jieba.initialize()
|
137 |
+
print("Word segmentation module jieba initialized.\n")
|
138 |
+
|
139 |
|
140 |
def convert_char_to_pinyin(text_list, polyphone=True):
|
141 |
final_text_list = []
|
142 |
+
custom_trans = str.maketrans(
|
143 |
+
{";": ",", "β": '"', "β": '"', "β": "'", "β": "'"}
|
144 |
+
) # add custom trans here, to address oov
|
145 |
+
|
146 |
+
def is_chinese(c):
|
147 |
+
return (
|
148 |
+
"\u3100" <= c <= "\u9fff" # common chinese characters
|
149 |
+
)
|
150 |
+
|
151 |
for text in text_list:
|
152 |
char_list = []
|
|
|
153 |
text = text.translate(custom_trans)
|
154 |
for seg in jieba.cut(text):
|
155 |
seg_byte_len = len(bytes(seg, "UTF-8"))
|
|
|
157 |
if char_list and seg_byte_len > 1 and char_list[-1] not in " :'\"":
|
158 |
char_list.append(" ")
|
159 |
char_list.extend(seg)
|
160 |
+
elif polyphone and seg_byte_len == 3 * len(seg): # if pure east asian characters
|
161 |
+
seg_ = lazy_pinyin(seg, style=Style.TONE3, tone_sandhi=True)
|
162 |
+
for i, c in enumerate(seg):
|
163 |
+
if is_chinese(c):
|
164 |
char_list.append(" ")
|
165 |
+
char_list.append(seg_[i])
|
166 |
+
else: # if mixed characters, alphabets and symbols
|
167 |
for c in seg:
|
168 |
if ord(c) < 256:
|
169 |
char_list.extend(c)
|
170 |
+
elif is_chinese(c):
|
171 |
+
char_list.append(" ")
|
172 |
+
char_list.extend(lazy_pinyin(c, style=Style.TONE3, tone_sandhi=True))
|
173 |
else:
|
174 |
+
char_list.append(c)
|
|
|
|
|
|
|
|
|
175 |
final_text_list.append(char_list)
|
176 |
|
177 |
return final_text_list
|