Spaces:
Build error
Build error
chnk58hoang
commited on
Commit
·
e076ae8
1
Parent(s):
02a1a35
initial commit
Browse files- .gitignore +1 -0
- README.md +4 -4
- app.py +31 -0
- requirements.txt +5 -0
- utils.py +94 -0
- vits/best_model_vits_22951.pth +3 -0
- vits/vits_config.json +255 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
__pycache__
|
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.4.1
|
8 |
app_file: app.py
|
|
|
1 |
---
|
2 |
+
title: MyOwnTexttospeech
|
3 |
+
emoji: 🐢
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: green
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.4.1
|
8 |
app_file: app.py
|
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from utils import load_model, normalize_text
|
4 |
+
|
5 |
+
|
6 |
+
vits_model = load_model()
|
7 |
+
vits_model.tts('Alo')
|
8 |
+
|
9 |
+
def text_to_speech(text):
|
10 |
+
text = normalize_text(text)
|
11 |
+
audio = vits_model.tts(text)
|
12 |
+
|
13 |
+
audio = np.array(audio)
|
14 |
+
return 16000,audio
|
15 |
+
|
16 |
+
gr.Interface(
|
17 |
+
fn=text_to_speech,
|
18 |
+
inputs="text",
|
19 |
+
outputs="audio",
|
20 |
+
|
21 |
+
examples=[
|
22 |
+
"Trăm năm trong cõi người ta, chữ tài chữ mệnh khéo là ghét nhau.",
|
23 |
+
"Đoạn trường tân thanh, thường được biết đến với cái tên đơn giản là Truyện Kiều, là một truyện thơ của đại thi hào Nguyễn Du",
|
24 |
+
"Lục Vân Tiên quê ở huyện Đông Thành, khôi ngô tuấn tú, tài kiêm văn võ. Nghe tin triều đình mở khoa thi, Vân Tiên từ giã thầy xuống núi đua tài.",
|
25 |
+
"Lê Quý Đôn, tên thuở nhỏ là Lê Danh Phương, là vị quan thời Lê trung hưng, cũng là nhà thơ và được mệnh danh là nhà bác học lớn của Việt Nam trong thời phong kiến",
|
26 |
+
"Tất cả mọi người đều sinh ra có quyền bình đẳng. Tạo hóa cho họ những quyền không ai có thể xâm phạm được; trong những quyền ấy, có quyền được sống, quyền tự do và quyền mưu cầu hạnh phúc.",
|
27 |
+
],
|
28 |
+
theme="default",
|
29 |
+
).launch(debug=False)
|
30 |
+
|
31 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.4.1
|
2 |
+
numpy==1.24.3
|
3 |
+
regex==2023.10.3
|
4 |
+
TTS==0.17.8
|
5 |
+
|
utils.py
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from TTS.api import TTS
|
2 |
+
import unicodedata
|
3 |
+
import regex
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
num_re = regex.compile(r"([0-9.,]*[0-9])")
|
9 |
+
digits = ["không", "một", "hai", "ba", "bốn", "năm", "sáu", "bảy", "tám", "chín"]
|
10 |
+
|
11 |
+
def read_number(num: str) -> str:
|
12 |
+
if len(num) == 1:
|
13 |
+
return digits[int(num)]
|
14 |
+
elif len(num) == 2 and num.isdigit():
|
15 |
+
n = int(num)
|
16 |
+
end = digits[n % 10]
|
17 |
+
if n == 10:
|
18 |
+
return "mười"
|
19 |
+
if n % 10 == 5:
|
20 |
+
end = "lăm"
|
21 |
+
if n % 10 == 0:
|
22 |
+
return digits[n // 10] + " mươi"
|
23 |
+
elif n < 20:
|
24 |
+
return "mười " + end
|
25 |
+
else:
|
26 |
+
if n % 10 == 1:
|
27 |
+
end = "mốt"
|
28 |
+
return digits[n // 10] + " mươi " + end
|
29 |
+
elif len(num) == 3 and num.isdigit():
|
30 |
+
n = int(num)
|
31 |
+
if n % 100 == 0:
|
32 |
+
return digits[n // 100] + " trăm"
|
33 |
+
elif num[1] == "0":
|
34 |
+
return digits[n // 100] + " trăm lẻ " + digits[n % 100]
|
35 |
+
else:
|
36 |
+
return digits[n // 100] + " trăm " + read_number(num[1:])
|
37 |
+
elif len(num) >= 4 and len(num) <= 6 and num.isdigit():
|
38 |
+
n = int(num)
|
39 |
+
n1 = n // 1000
|
40 |
+
return read_number(str(n1)) + " ngàn " + read_number(num[-3:])
|
41 |
+
elif "," in num:
|
42 |
+
n1, n2 = num.split(",")
|
43 |
+
return read_number(n1) + " phẩy " + read_number(n2)
|
44 |
+
elif "." in num:
|
45 |
+
parts = num.split(".")
|
46 |
+
if len(parts) == 2:
|
47 |
+
if parts[1] == "000":
|
48 |
+
return read_number(parts[0]) + " ngàn"
|
49 |
+
elif parts[1].startswith("00"):
|
50 |
+
end = digits[int(parts[1][2:])]
|
51 |
+
return read_number(parts[0]) + " ngàn lẻ " + end
|
52 |
+
else:
|
53 |
+
return read_number(parts[0]) + " ngàn " + read_number(parts[1])
|
54 |
+
elif len(parts) == 3:
|
55 |
+
return (
|
56 |
+
read_number(parts[0])
|
57 |
+
+ " triệu "
|
58 |
+
+ read_number(parts[1])
|
59 |
+
+ " ngàn "
|
60 |
+
+ read_number(parts[2])
|
61 |
+
)
|
62 |
+
return num
|
63 |
+
|
64 |
+
|
65 |
+
def load_model():
|
66 |
+
config_path = 'vits/vits_config.json'
|
67 |
+
checkpoint_path = 'vits/best_model_vits_22951.pth'
|
68 |
+
|
69 |
+
tts = TTS(model_name='my_tts',
|
70 |
+
model_path=checkpoint_path,
|
71 |
+
config_path=config_path)
|
72 |
+
|
73 |
+
return tts
|
74 |
+
|
75 |
+
|
76 |
+
def normalize_text(text):
|
77 |
+
# lowercase
|
78 |
+
text = text.lower()
|
79 |
+
# unicode normalize
|
80 |
+
text = unicodedata.normalize("NFKC", text)
|
81 |
+
text = text.replace(".", "")
|
82 |
+
text = text.replace(",", "")
|
83 |
+
text = text.replace(";", "")
|
84 |
+
text = text.replace(":", "")
|
85 |
+
text = text.replace("!", "")
|
86 |
+
text = text.replace("?", "")
|
87 |
+
text = text.replace("(", "")
|
88 |
+
|
89 |
+
text = num_re.sub(r" \1 ", text)
|
90 |
+
words = text.split()
|
91 |
+
words = [read_number(w) if num_re.fullmatch(w) else w for w in words]
|
92 |
+
text = " ".join(words)
|
93 |
+
|
94 |
+
return text
|
vits/best_model_vits_22951.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0dfc9c3865ccf2359258c5c6e2145365e643ba3be0208b57efedb6bfac20e428
|
3 |
+
size 997817797
|
vits/vits_config.json
ADDED
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
8 |
+
"plot_step": 100,
|
9 |
+
"model_param_stats": false,
|
10 |
+
"wandb_entity": null,
|
11 |
+
"dashboard_logger": "tensorboard",
|
12 |
+
"save_on_interrupt": true,
|
13 |
+
"log_model_step": null,
|
14 |
+
"save_step": 10000,
|
15 |
+
"save_n_checkpoints": 5,
|
16 |
+
"save_checkpoints": true,
|
17 |
+
"save_all_best": false,
|
18 |
+
"save_best_after": 10000,
|
19 |
+
"target_loss": null,
|
20 |
+
"print_eval": true,
|
21 |
+
"test_delay_epochs": -1,
|
22 |
+
"run_eval": true,
|
23 |
+
"run_eval_steps": null,
|
24 |
+
"distributed_backend": "nccl",
|
25 |
+
"distributed_url": "tcp://localhost:54321",
|
26 |
+
"mixed_precision": true,
|
27 |
+
"precision": "fp16",
|
28 |
+
"epochs": 2000,
|
29 |
+
"batch_size": 32,
|
30 |
+
"eval_batch_size": 16,
|
31 |
+
"grad_clip": [
|
32 |
+
1000,
|
33 |
+
1000
|
34 |
+
],
|
35 |
+
"scheduler_after_epoch": true,
|
36 |
+
"lr": 0.001,
|
37 |
+
"optimizer": "AdamW",
|
38 |
+
"optimizer_params": {
|
39 |
+
"betas": [
|
40 |
+
0.8,
|
41 |
+
0.99
|
42 |
+
],
|
43 |
+
"eps": 1e-09,
|
44 |
+
"weight_decay": 0.01
|
45 |
+
},
|
46 |
+
"lr_scheduler": null,
|
47 |
+
"lr_scheduler_params": null,
|
48 |
+
"use_grad_scaler": false,
|
49 |
+
"allow_tf32": false,
|
50 |
+
"cudnn_enable": true,
|
51 |
+
"cudnn_deterministic": false,
|
52 |
+
"cudnn_benchmark": false,
|
53 |
+
"training_seed": 54321,
|
54 |
+
"model": "vits",
|
55 |
+
"num_loader_workers": 4,
|
56 |
+
"num_eval_loader_workers": 4,
|
57 |
+
"use_noise_augment": false,
|
58 |
+
"audio": {
|
59 |
+
"fft_size": 1024,
|
60 |
+
"sample_rate": 16000,
|
61 |
+
"win_length": 1024,
|
62 |
+
"hop_length": 256,
|
63 |
+
"num_mels": 80,
|
64 |
+
"mel_fmin": 0,
|
65 |
+
"mel_fmax": null
|
66 |
+
},
|
67 |
+
"use_phonemes": false,
|
68 |
+
"phonemizer": null,
|
69 |
+
"phoneme_language": null,
|
70 |
+
"compute_input_seq_cache": true,
|
71 |
+
"text_cleaner": null,
|
72 |
+
"enable_eos_bos_chars": false,
|
73 |
+
"test_sentences_file": "",
|
74 |
+
"phoneme_cache_path": null,
|
75 |
+
"characters": {
|
76 |
+
"characters_class": "TTS.tts.utils.text.characters.Graphemes",
|
77 |
+
"vocab_dict": null,
|
78 |
+
"pad": "<PAD>",
|
79 |
+
"eos": "<EOS>",
|
80 |
+
"bos": "<BOS>",
|
81 |
+
"blank": "<BLNK>",
|
82 |
+
"characters": "abcdefghijklmnopqrstuvwxyz\u00e0\u00e1\u00e2\u00e3\u00e8\u00e9\u00ea\u00ec\u00ed\u00f2\u00f3\u00f4\u00f5\u00f9\u00fa\u00fd\u0103\u0111\u0129\u0169\u01a1\u01b0\u1ea1\u1ea3\u1ea5\u1ea7\u1ea9\u1eab\u1ead\u1eaf\u1eb1\u1eb3\u1eb5\u1eb7\u1eb9\u1ebb\u1ebd\u1ebf\u1ec1\u1ec3\u1ec5\u1ec7\u1ec9\u1ecb\u1ecd\u1ecf\u1ed1\u1ed3\u1ed5\u1ed7\u1ed9\u1edb\u1edd\u1edf\u1ee1\u1ee3\u1ee5\u1ee7\u1ee9\u1eeb\u1eed\u1eef\u1ef1\u1ef3\u1ef5\u1ef7\u1ef9",
|
83 |
+
"punctuations": "!'(),-.:;? ",
|
84 |
+
"phonemes": null,
|
85 |
+
"is_unique": true,
|
86 |
+
"is_sorted": true
|
87 |
+
},
|
88 |
+
"add_blank": true,
|
89 |
+
"batch_group_size": 5,
|
90 |
+
"loss_masking": null,
|
91 |
+
"min_audio_len": 1,
|
92 |
+
"max_audio_len": Infinity,
|
93 |
+
"min_text_len": 1,
|
94 |
+
"max_text_len": Infinity,
|
95 |
+
"compute_f0": false,
|
96 |
+
"compute_energy": false,
|
97 |
+
"compute_linear_spec": true,
|
98 |
+
"precompute_num_workers": 0,
|
99 |
+
"start_by_longest": false,
|
100 |
+
"shuffle": false,
|
101 |
+
"drop_last": false,
|
102 |
+
"datasets": [
|
103 |
+
{
|
104 |
+
"formatter": "",
|
105 |
+
"dataset_name": "",
|
106 |
+
"path": "/kaggle/input/infore/inforedataset",
|
107 |
+
"meta_file_train": "metadata.tsv",
|
108 |
+
"ignored_speakers": null,
|
109 |
+
"language": "",
|
110 |
+
"phonemizer": "",
|
111 |
+
"meta_file_val": "",
|
112 |
+
"meta_file_attn_mask": ""
|
113 |
+
}
|
114 |
+
],
|
115 |
+
"test_sentences": [
|
116 |
+
"xin ch\u00e0o, t\u1ea5t c\u1ea3 m\u1ecdi ng\u01b0\u1eddi"
|
117 |
+
],
|
118 |
+
"eval_split_max_size": null,
|
119 |
+
"eval_split_size": 0.01,
|
120 |
+
"use_speaker_weighted_sampler": false,
|
121 |
+
"speaker_weighted_sampler_alpha": 1.0,
|
122 |
+
"use_language_weighted_sampler": false,
|
123 |
+
"language_weighted_sampler_alpha": 1.0,
|
124 |
+
"use_length_weighted_sampler": false,
|
125 |
+
"length_weighted_sampler_alpha": 1.0,
|
126 |
+
"model_args": {
|
127 |
+
"num_chars": 108,
|
128 |
+
"out_channels": 513,
|
129 |
+
"spec_segment_size": 32,
|
130 |
+
"hidden_channels": 192,
|
131 |
+
"hidden_channels_ffn_text_encoder": 768,
|
132 |
+
"num_heads_text_encoder": 2,
|
133 |
+
"num_layers_text_encoder": 6,
|
134 |
+
"kernel_size_text_encoder": 3,
|
135 |
+
"dropout_p_text_encoder": 0.1,
|
136 |
+
"dropout_p_duration_predictor": 0.5,
|
137 |
+
"kernel_size_posterior_encoder": 5,
|
138 |
+
"dilation_rate_posterior_encoder": 1,
|
139 |
+
"num_layers_posterior_encoder": 16,
|
140 |
+
"kernel_size_flow": 5,
|
141 |
+
"dilation_rate_flow": 1,
|
142 |
+
"num_layers_flow": 4,
|
143 |
+
"resblock_type_decoder": "1",
|
144 |
+
"resblock_kernel_sizes_decoder": [
|
145 |
+
3,
|
146 |
+
7,
|
147 |
+
11
|
148 |
+
],
|
149 |
+
"resblock_dilation_sizes_decoder": [
|
150 |
+
[
|
151 |
+
1,
|
152 |
+
3,
|
153 |
+
5
|
154 |
+
],
|
155 |
+
[
|
156 |
+
1,
|
157 |
+
3,
|
158 |
+
5
|
159 |
+
],
|
160 |
+
[
|
161 |
+
1,
|
162 |
+
3,
|
163 |
+
5
|
164 |
+
]
|
165 |
+
],
|
166 |
+
"upsample_rates_decoder": [
|
167 |
+
8,
|
168 |
+
8,
|
169 |
+
2,
|
170 |
+
2
|
171 |
+
],
|
172 |
+
"upsample_initial_channel_decoder": 512,
|
173 |
+
"upsample_kernel_sizes_decoder": [
|
174 |
+
16,
|
175 |
+
16,
|
176 |
+
4,
|
177 |
+
4
|
178 |
+
],
|
179 |
+
"periods_multi_period_discriminator": [
|
180 |
+
2,
|
181 |
+
3,
|
182 |
+
5,
|
183 |
+
7,
|
184 |
+
11
|
185 |
+
],
|
186 |
+
"use_sdp": true,
|
187 |
+
"noise_scale": 1.0,
|
188 |
+
"inference_noise_scale": 0.667,
|
189 |
+
"length_scale": 1,
|
190 |
+
"noise_scale_dp": 1.0,
|
191 |
+
"inference_noise_scale_dp": 1.0,
|
192 |
+
"max_inference_len": null,
|
193 |
+
"init_discriminator": true,
|
194 |
+
"use_spectral_norm_disriminator": false,
|
195 |
+
"use_speaker_embedding": false,
|
196 |
+
"num_speakers": 0,
|
197 |
+
"speakers_file": null,
|
198 |
+
"d_vector_file": null,
|
199 |
+
"speaker_embedding_channels": 256,
|
200 |
+
"use_d_vector_file": false,
|
201 |
+
"d_vector_dim": 0,
|
202 |
+
"detach_dp_input": true,
|
203 |
+
"use_language_embedding": false,
|
204 |
+
"embedded_language_dim": 4,
|
205 |
+
"num_languages": 0,
|
206 |
+
"language_ids_file": null,
|
207 |
+
"use_speaker_encoder_as_loss": false,
|
208 |
+
"speaker_encoder_config_path": "",
|
209 |
+
"speaker_encoder_model_path": "",
|
210 |
+
"condition_dp_on_speaker": true,
|
211 |
+
"freeze_encoder": false,
|
212 |
+
"freeze_DP": false,
|
213 |
+
"freeze_PE": false,
|
214 |
+
"freeze_flow_decoder": false,
|
215 |
+
"freeze_waveform_decoder": false,
|
216 |
+
"encoder_sample_rate": null,
|
217 |
+
"interpolate_z": true,
|
218 |
+
"reinit_DP": false,
|
219 |
+
"reinit_text_encoder": false
|
220 |
+
},
|
221 |
+
"lr_gen": 0.0001,
|
222 |
+
"lr_disc": 0.0001,
|
223 |
+
"lr_scheduler_gen": "ExponentialLR",
|
224 |
+
"lr_scheduler_gen_params": {
|
225 |
+
"gamma": 0.999875,
|
226 |
+
"last_epoch": -1
|
227 |
+
},
|
228 |
+
"lr_scheduler_disc": "ExponentialLR",
|
229 |
+
"lr_scheduler_disc_params": {
|
230 |
+
"gamma": 0.999875,
|
231 |
+
"last_epoch": -1
|
232 |
+
},
|
233 |
+
"kl_loss_alpha": 1.0,
|
234 |
+
"disc_loss_alpha": 1.0,
|
235 |
+
"gen_loss_alpha": 1.0,
|
236 |
+
"feat_loss_alpha": 1.0,
|
237 |
+
"mel_loss_alpha": 45.0,
|
238 |
+
"dur_loss_alpha": 1.0,
|
239 |
+
"speaker_encoder_loss_alpha": 1.0,
|
240 |
+
"return_wav": true,
|
241 |
+
"use_weighted_sampler": false,
|
242 |
+
"weighted_sampler_attrs": null,
|
243 |
+
"weighted_sampler_multipliers": null,
|
244 |
+
"r": 1,
|
245 |
+
"num_speakers": 0,
|
246 |
+
"use_speaker_embedding": false,
|
247 |
+
"speakers_file": null,
|
248 |
+
"speaker_embedding_channels": 256,
|
249 |
+
"language_ids_file": null,
|
250 |
+
"use_language_embedding": false,
|
251 |
+
"use_d_vector_file": false,
|
252 |
+
"d_vector_file": null,
|
253 |
+
"d_vector_dim": 0,
|
254 |
+
"github_branch": "* master"
|
255 |
+
}
|