Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,14 @@ from text import text_to_sequence
|
|
9 |
import numpy as np
|
10 |
import os
|
11 |
import translators.server as tss
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def get_text(text, hps):
|
13 |
text_norm = text_to_sequence(text, hps.data.text_cleaners)
|
14 |
if hps.data.add_blank:
|
@@ -16,6 +24,7 @@ def get_text(text, hps):
|
|
16 |
text_norm = torch.LongTensor(text_norm)
|
17 |
return text_norm
|
18 |
|
|
|
19 |
hps = utils.get_hparams_from_file("./configs/uma87.json")
|
20 |
net_g = SynthesizerTrn(
|
21 |
len(symbols),
|
@@ -25,29 +34,10 @@ net_g = SynthesizerTrn(
|
|
25 |
**hps.model)
|
26 |
_ = net_g.eval()
|
27 |
|
28 |
-
_ = utils.load_checkpoint("pretrained_models/
|
29 |
-
|
30 |
-
title = "Umamusume voice synthesizer \n 赛马娘语音合成器"
|
31 |
-
description = """
|
32 |
-
This synthesizer is created based on [VITS][paper] model, trained on voice data extracted from mobile game Umamusume Pretty Derby\n
|
33 |
-
这个合成器是基于VITS文本到语音模型,在从手游《賽馬娘:Pretty Derby》解包的语音数据上训练得到。\n
|
34 |
-
[introduction video][video] [模型介绍视频][video]\n
|
35 |
-
Due to some unknown reason, VITS inference on CPU results in accumulative memory leakage, resulting in Runtime error:Memory limit exceeded.\n
|
36 |
-
In case of space crash, you may duplicate this space or [open in Colab][colab] to run it privately and without any queue.\n
|
37 |
-
由于未知原因,VITS模型在CPU上执行推理时会有逐步累积的内存泄漏,最终导致空间报错Runtime error:Memory limit exceeded,目前正在排查。\n
|
38 |
-
以防该空间崩溃,您可以复制该空间至私人空间运行或打开[Google Colab][colab]在线运行。\n
|
39 |
-
If your input language is not Japanese, it will be translated to Japanese by Google translator, but accuracy is not guaranteed.\n
|
40 |
-
如果您的输入语言不是日语,则会由谷歌翻译自动翻译为日语,但是准确性不能保证。\n\n
|
41 |
-
[video]: https://www.bilibili.com/video/BV1T84y1e7p5/?vd_source=6d5c00c796eff1cbbe25f1ae722c2f9f#reply607277701
|
42 |
-
[paper]: https://arxiv.org/abs/2106.06103
|
43 |
-
[colab]: https://colab.research.google.com/drive/1J2Vm5dczTF99ckyNLXV0K-hQTxLwEaj5?usp=sharing
|
44 |
-
"""
|
45 |
-
article = """
|
46 |
-
|
47 |
-
"""
|
48 |
-
|
49 |
|
50 |
def infer(text, character, language, duration, noise_scale, noise_scale_w):
|
|
|
51 |
if language == '日本語':
|
52 |
pass
|
53 |
elif language == '简体中文':
|
@@ -60,50 +50,81 @@ def infer(text, character, language, duration, noise_scale, noise_scale_w):
|
|
60 |
x_tst = stn_tst.unsqueeze(0)
|
61 |
x_tst_lengths = torch.LongTensor([stn_tst.size(0)])
|
62 |
sid = torch.LongTensor([char_id])
|
63 |
-
audio = net_g.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=noise_scale, noise_scale_w=noise_scale_w,
|
64 |
-
|
|
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
textbox = gr.Textbox(label="Text", placeholder="Type your sentence here", lines=2)
|
68 |
-
# select character
|
69 |
-
char_dropdown = gr.Dropdown(['0:特别周','1:无声铃鹿','2:东海帝王','3:丸善斯基',
|
70 |
-
'4:富士奇迹','5:小栗帽','6:黄金船','7:伏特加',
|
71 |
-
'8:大和赤骥','9:大树快车','10:草上飞','11:菱亚马逊',
|
72 |
-
'12:目白麦昆','13:神鹰','14:好歌剧','15:成田白仁',
|
73 |
-
'16:鲁道夫象征','17:气槽','18:爱丽数码','19:青云天空',
|
74 |
-
'20:玉藻十字','21:美妙姿势','22:琵琶晨光','23:重炮',
|
75 |
-
'24:曼城茶座','25:美普波旁','26:目白雷恩','27:菱曙',
|
76 |
-
'28:雪之美人','29:米浴','30:艾尼斯风神','31:爱丽速子',
|
77 |
-
'32:爱慕织姬','33:稻荷一','34:胜利奖券','35:空中神宫',
|
78 |
-
'36:荣进闪耀','37:真机伶','38:川上公主','39:黄金城市',
|
79 |
-
'40:樱花进王','41:采珠','42:新光风','43:东商变革',
|
80 |
-
'44:超级小溪','45:醒目飞鹰','46:荒漠英雄','47:东瀛佐敦',
|
81 |
-
'48:中山庆典','49:成田大进','50:西野花','51:春乌拉拉',
|
82 |
-
'52:青竹回忆','53:微光飞驹','54:美丽周日','55:待兼福来',
|
83 |
-
'56:Mr.C.B','57:名将怒涛','58:目白多伯','59:优秀素质',
|
84 |
-
'60:帝王光环','61:待兼诗歌剧','62:生野狄杜斯','63:目白善信',
|
85 |
-
'64:大拓太阳神','65:双涡轮','66:里见光钻','67:北部玄驹',
|
86 |
-
'68:樱花千代王','69:天狼星象征','70:目白阿尔丹','71:八重无敌',
|
87 |
-
'72:鹤丸刚志','73:目白光明','74:樱花桂冠','75:成田路',
|
88 |
-
'76:也文摄辉','77:吉兆','78:谷野美酒','79:第一红宝石',
|
89 |
-
'80:真弓快车','81:骏川手纲','82:凯斯奇迹','83:小林历奇',
|
90 |
-
'84:北港火山','85:奇锐骏','86:秋川理事长'])
|
91 |
-
language_dropdown = gr.Dropdown(['日本語','简体中文','English'])
|
92 |
-
examples = [['お疲れ様です,トレーナーさん。', '1:无声铃鹿', '日本語', 1, 0.667, 0.8],
|
93 |
-
['張り切っていこう!', '67:北部玄驹', '日本語', 1, 0.667, 0.8],
|
94 |
-
['何でこんなに慣れでんのよ,私のほが先に好きだっだのに。', '10:草上飞','日本語', 1, 0.667, 0.8],
|
95 |
-
['授業中に出しだら,学校生活終わるですわ。', '12:目白麦昆','日本語', 1, 0.667, 0.8],
|
96 |
-
['お帰りなさい,お兄様!', '29:米浴','日本語', 1, 0.667, 0.8],
|
97 |
-
['私の処女をもらっでください!', '29:米浴','日本語', 1, 0.667, 0.8]]
|
98 |
-
|
99 |
-
duration_slider = gr.Slider(minimum=0.1, maximum=5, value=1, step=0.1, label='时长 Duration')
|
100 |
-
noise_scale_slider = gr.Slider(minimum=0.1, maximum=5, value=0.667, step=0.001, label='噪声比例 noise_scale')
|
101 |
-
noise_scale_w_slider = gr.Slider(minimum=0.1, maximum=5, value=0.8, step=0.1, label='噪声偏差 noise_scale_w')
|
102 |
-
|
103 |
-
app = gr.Interface(fn=infer, inputs=[textbox, char_dropdown, language_dropdown, duration_slider, noise_scale_slider, noise_scale_w_slider,], outputs=["text","audio"],title=title, description=description, article=article, examples=examples)
|
104 |
-
|
105 |
-
if __name__=="__main__":
|
106 |
parser = argparse.ArgumentParser()
|
107 |
parser.add_argument("--share", action="store_true", default=False, help="share gradio app")
|
108 |
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
app.queue(concurrency_count=3).launch(show_api=False, share=args.share)
|
|
|
9 |
import numpy as np
|
10 |
import os
|
11 |
import translators.server as tss
|
12 |
+
def show_memory_info(hint):
|
13 |
+
pid = os.getpid()
|
14 |
+
p = psutil.Process(pid)
|
15 |
+
info = p.memory_info()
|
16 |
+
memory = info.rss / 1024.0 / 1024
|
17 |
+
print("{} 内存占用: {} MB".format(hint, memory))
|
18 |
+
|
19 |
+
|
20 |
def get_text(text, hps):
|
21 |
text_norm = text_to_sequence(text, hps.data.text_cleaners)
|
22 |
if hps.data.add_blank:
|
|
|
24 |
text_norm = torch.LongTensor(text_norm)
|
25 |
return text_norm
|
26 |
|
27 |
+
|
28 |
hps = utils.get_hparams_from_file("./configs/uma87.json")
|
29 |
net_g = SynthesizerTrn(
|
30 |
len(symbols),
|
|
|
34 |
**hps.model)
|
35 |
_ = net_g.eval()
|
36 |
|
37 |
+
_ = utils.load_checkpoint("pretrained_models/uma_1153000.pth", net_g, None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
def infer(text, character, language, duration, noise_scale, noise_scale_w):
|
40 |
+
show_memory_info("infer调用前")
|
41 |
if language == '日本語':
|
42 |
pass
|
43 |
elif language == '简体中文':
|
|
|
50 |
x_tst = stn_tst.unsqueeze(0)
|
51 |
x_tst_lengths = torch.LongTensor([stn_tst.size(0)])
|
52 |
sid = torch.LongTensor([char_id])
|
53 |
+
audio = net_g.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=noise_scale, noise_scale_w=noise_scale_w,
|
54 |
+
length_scale=duration)[0][0, 0].data.cpu().float().numpy()
|
55 |
+
del stn_tst, x_tst, x_tst_lengths, sid
|
56 |
+
show_memory_info("infer调用后")
|
57 |
+
return (text, (22050, audio))
|
58 |
|
59 |
+
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
parser = argparse.ArgumentParser()
|
61 |
parser.add_argument("--share", action="store_true", default=False, help="share gradio app")
|
62 |
args = parser.parse_args()
|
63 |
+
app = gr.Blocks()
|
64 |
+
with app:
|
65 |
+
gr.Markdown("# Umamusume voice synthesizer 赛马娘语音合成器\n\n"
|
66 |
+
"![visitor badge](https://visitor-badge.glitch.me/badge?page_id=Plachta.VITS-Umamusume-voice-synthesizer)\n\n"
|
67 |
+
"This synthesizer is created based on [VITS](https://arxiv.org/abs/2106.06103) model, trained on voice data extracted from mobile game Umamusume Pretty Derby \n\n"
|
68 |
+
"这个合成器是基于VITS文本到语音模型,在从手游《賽馬娘:Pretty Derby》解包的语音数据上训练得到。\n\n"
|
69 |
+
"[introduction video / 模型介绍视频](https://www.bilibili.com/video/BV1T84y1e7p5/?vd_source=6d5c00c796eff1cbbe25f1ae722c2f9f#reply607277701)\n\n"
|
70 |
+
"Due to some unknown reason, VITS inference on CPU results in accumulative memory leakage, resulting in Runtime error:Memory limit exceeded.\n\n"
|
71 |
+
"In case of space crash, you may duplicate this space or [open in Colab](https://colab.research.google.com/drive/1J2Vm5dczTF99ckyNLXV0K-hQTxLwEaj5?usp=sharing) to run it privately and without any queue.\n\n"
|
72 |
+
"由于未知原因,VITS模型在CPU上执行推理时会有逐步累积的内存泄漏,最终导致空间报错Runtime error:Memory limit exceeded,目前正在排查。\n\n"
|
73 |
+
"以防该空间崩溃,您可以复制该空间至私人空间运行或打开[Google Colab](https://colab.research.google.com/drive/1J2Vm5dczTF99ckyNLXV0K-hQTxLwEaj5?usp=sharing)在线运行。\n\n"
|
74 |
+
"If your input language is not Japanese, it will be translated to Japanese by Google translator, but accuracy is not guaranteed.\n\n"
|
75 |
+
"如果您的输入语言不是日语,则会由谷歌翻译自动翻译为日语,但是准确性不能保证。\n\n"
|
76 |
+
)
|
77 |
+
with gr.Row():
|
78 |
+
with gr.Column():
|
79 |
+
# We instantiate the Textbox class
|
80 |
+
textbox = gr.Textbox(label="Text", placeholder="Type your sentence here", lines=2)
|
81 |
+
# select character
|
82 |
+
char_dropdown = gr.Dropdown(choices=['0:特别周', '1:无声铃鹿', '2:东海帝王', '3:丸善斯基',
|
83 |
+
'4:富士奇迹', '5:小栗帽', '6:黄金船', '7:伏特加',
|
84 |
+
'8:大和赤骥', '9:大树快车', '10:草上飞', '11:菱亚马逊',
|
85 |
+
'12:目白麦昆', '13:神鹰', '14:好歌剧', '15:成田白仁',
|
86 |
+
'16:鲁道夫象征', '17:气槽', '18:爱丽数码', '19:青云天空',
|
87 |
+
'20:玉藻十字', '21:美妙姿势', '22:琵琶晨光', '23:重炮',
|
88 |
+
'24:曼城茶座', '25:美普波旁', '26:目白雷恩', '27:菱曙',
|
89 |
+
'28:雪之美人', '29:米浴', '30:艾尼斯风神', '31:爱丽速子',
|
90 |
+
'32:爱慕织姬', '33:稻荷一', '34:胜利奖券', '35:空中神宫',
|
91 |
+
'36:荣进闪耀', '37:真机伶', '38:川上公主', '39:黄金城市',
|
92 |
+
'40:樱花进王', '41:采珠', '42:新光风', '43:东商变革',
|
93 |
+
'44:超级小溪', '45:醒目飞鹰', '46:荒漠英雄', '47:东瀛佐敦',
|
94 |
+
'48:中山庆典', '49:成田大进', '50:西野花', '51:春乌拉拉',
|
95 |
+
'52:青竹回忆', '53:微光飞驹', '54:美丽周日', '55:待兼福来',
|
96 |
+
'56:Mr.C.B', '57:名将怒涛', '58:目白多伯', '59:优秀素质',
|
97 |
+
'60:帝王光环', '61:待兼诗歌剧', '62:生野狄杜斯', '63:目白善信',
|
98 |
+
'64:大拓太阳神', '65:双涡轮', '66:里见光钻', '67:北部玄驹',
|
99 |
+
'68:樱花千代王', '69:天狼星象征', '70:目白阿尔丹', '71:八重无敌',
|
100 |
+
'72:鹤丸刚志', '73:目白光明', '74:樱花桂冠', '75:成田路',
|
101 |
+
'76:也文摄辉', '77:吉兆', '78:谷野美酒', '79:第一红宝石',
|
102 |
+
'80:真弓快车', '81:骏川手纲', '82:凯斯奇迹', '83:小林历奇',
|
103 |
+
'84:北港火山', '85:奇锐骏', '86:秋川理事长'], label='character')
|
104 |
+
language_dropdown = gr.Dropdown(choices=['日本語', '简体中文', 'English'], label='language')
|
105 |
+
|
106 |
+
|
107 |
+
duration_slider = gr.Slider(minimum=0.1, maximum=5, value=1, step=0.1, label='时长 Duration')
|
108 |
+
noise_scale_slider = gr.Slider(minimum=0.1, maximum=5, value=0.667, step=0.001, label='噪声比例 noise_scale')
|
109 |
+
noise_scale_w_slider = gr.Slider(minimum=0.1, maximum=5, value=0.8, step=0.1, label='噪声偏差 noise_scale_w')
|
110 |
+
with gr.Column():
|
111 |
+
text_output = gr.Textbox(label="Output Text")
|
112 |
+
audio_output = gr.Audio(label="Output Voice")
|
113 |
+
btn = gr.Button("Generate!")
|
114 |
+
btn.click(infer, inputs=[textbox, char_dropdown, language_dropdown,
|
115 |
+
duration_slider, noise_scale_slider, noise_scale_w_slider],
|
116 |
+
outputs=[text_output, audio_output])
|
117 |
+
examples = [['お疲れ様です,トレーナーさん。', '1:无声铃鹿', '日本語', 1, 0.667, 0.8],
|
118 |
+
['張り切っていこう!', '67:北部玄驹', '日本語', 1, 0.667, 0.8],
|
119 |
+
['何でこんなに慣れでんのよ,私のほが先に好きだっだのに。', '10:草上飞', '日本語', 1, 0.667, 0.8],
|
120 |
+
['授業中に出しだら,学校生活終わるですわ。', '12:目白麦昆', '日本語', 1, 0.667, 0.8],
|
121 |
+
['お帰りなさい,お兄様!', '29:米浴', '日本語', 1, 0.667, 0.8],
|
122 |
+
['私の処女をもらっでください!', '29:米浴', '日本語', 1, 0.667, 0.8]]
|
123 |
+
gr.Examples(
|
124 |
+
examples=examples,
|
125 |
+
inputs=[textbox, char_dropdown, language_dropdown,
|
126 |
+
duration_slider, noise_scale_slider,noise_scale_w_slider],
|
127 |
+
outputs=[text_output, audio_output],
|
128 |
+
fn=infer
|
129 |
+
)
|
130 |
app.queue(concurrency_count=3).launch(show_api=False, share=args.share)
|