Plachta commited on
Commit
210468c
1 Parent(s): c1f76ae

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -0
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import IPython.display as ipd
3
+
4
+ import os
5
+ import json
6
+ import math
7
+ import torch
8
+ from torch import nn
9
+ from torch.nn import functional as F
10
+ from torch.utils.data import DataLoader
11
+ import translators as ts
12
+
13
+ import commons
14
+ import utils
15
+ from data_utils import TextAudioLoader, TextAudioCollate, TextAudioSpeakerLoader, TextAudioSpeakerCollate
16
+ from models import SynthesizerTrn
17
+ from text.symbols import symbols
18
+ from text import text_to_sequence
19
+ import gradio as gr
20
+
21
+ from scipy.io.wavfile import write
22
+
23
+
24
+ def get_text(text, hps):
25
+ text_norm = text_to_sequence(text, hps.data.text_cleaners)
26
+ if hps.data.add_blank:
27
+ text_norm = commons.intersperse(text_norm, 0)
28
+ text_norm = torch.LongTensor(text_norm)
29
+ return text_norm
30
+
31
+ hps = utils.get_hparams_from_file("./configs/uma87.json")
32
+ net_g = SynthesizerTrn(
33
+ len(symbols),
34
+ hps.data.filter_length // 2 + 1,
35
+ hps.train.segment_size // hps.data.hop_length,
36
+ n_speakers=hps.data.n_speakers,
37
+ **hps.model)
38
+ _ = net_g.eval()
39
+
40
+ _ = utils.load_checkpoint("pretrained_models/uma87_639000.pth", net_g, None)
41
+
42
+ title = "Umamusume voice synthesizer \n 赛马娘语音合成器"
43
+ description = """
44
+ 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
45
+ 这个合成器是基于VITS文本到语音模型,在从手游《賽馬娘:Pretty Derby》解包的语音数据上训练得到。
46
+ <img src="https://huggingface.co/spaces/Plachta/uma_voice/blob/main/small_202201136190132.jpg">
47
+ """
48
+ article = """
49
+ If your input language is not Japanese, it will be translated to Japanese by Google translator, but accuracy is not guaranteed.\n
50
+ 如果您的输入语言不是日语,则会由谷歌翻译自动翻译为日语,但是准确性不能保证。
51
+ """
52
+ def infer(text, character, language):
53
+ if language == '日本語':
54
+ pass
55
+ elif language == '简体中文':
56
+ text = ts.google(text, from_language='zh', to_language-'ja')
57
+ elif language == 'English':
58
+ text = ts.google(text, from_language='en', to_language-'ja')
59
+ char_id = int(character.split(':')[0])
60
+ stn_tst = get_text(text, hps)
61
+ with torch.no_grad():
62
+ x_tst = stn_tst.cuda().unsqueeze(0)
63
+ x_tst_lengths = torch.LongTensor([stn_tst.size(0)]).cuda()
64
+ sid = torch.LongTensor([char_id]).cuda()
65
+ audio = net_g.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=.667, noise_scale_w=0.8, length_scale=1)[0][0,0].data.cpu().float().numpy()
66
+ return (text,(22050, audio))
67
+
68
+ # We instantiate the Textbox class
69
+ textbox = gr.Textbox(label="Type your sentence here:", placeholder="お疲れ様です,トレーナーさん。", lines=2)
70
+ # select character
71
+ char_dropdown = gr.Dropdown(['0:特别周','1:无声铃鹿','2:东海帝王','3:丸善斯基',
72
+ '4:富士奇迹','5:小栗帽','6:黄金船','7:伏特加',
73
+ '8:大和赤骥','9:大树快车','10:草上飞','11:菱亚马逊',
74
+ '12:目白麦昆','13:神鹰','14:好歌剧','15:成田白仁',
75
+ '16:鲁道夫象征','17:气槽','18:爱丽数码','19:青云天空',
76
+ '20:玉藻十字','21:美妙姿势','22:琵琶晨光','23:重炮',
77
+ '24:曼城茶座','25:美普波旁','26:目白雷恩','27:菱曙',
78
+ '28:雪之美人','29:米浴','30:艾尼斯风神','31:爱丽速子',
79
+ '32:爱慕织姬','33:稻荷一','34:胜利奖券','35:空中神宫',
80
+ '36:荣进闪耀','37:真机伶','38:川上公主','39:黄金城市',
81
+ '40:樱花进王','41:采珠','42:新光风','43:东商变革',
82
+ '44:超级小溪','45:醒目飞鹰','46:荒漠英雄','47:东瀛佐敦',
83
+ '48:中山庆典','49:成田大进','50:西野花','51:春乌拉拉',
84
+ '52:青竹回忆','53:微光飞驹','54:美丽周日','55:待兼福来',
85
+ '56:Mr.C.B','57:名将怒涛','58:目白多伯','59:优秀素质',
86
+ '60:帝王光环','61:待兼诗歌剧','62:生野狄杜斯','63:目白善信',
87
+ '64:大拓太阳神','65:双涡轮','66:里见光钻','67:北部玄驹',
88
+ '68:樱花千代王','69:天狼星象征','70:目白阿尔丹','71:八重无敌',
89
+ '72:鹤丸刚志','73:目白光明','74:樱花桂冠','75:成田路',
90
+ '76:也文摄辉','77:吉兆','78:谷野美酒','79:第一红宝石',
91
+ '80:真弓快车','81:骏川手纲','82:凯斯奇迹','83:小林历奇',
92
+ '84:北港火山','85:奇锐骏','86:秋川理事长'])
93
+ language_dropdown = gr.Dropdown(['日本語','简体中文','English'])
94
+
95
+ gr.Interface(fn=infer, inputs=[textbox, char_dropdown, language_dropdown], outputs=["text","audio"],
96
+ title=title, description=description, article=article).launch()