Mahiruoshi commited on
Commit
05f8fbb
1 Parent(s): 13c3b46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -130,22 +130,27 @@ def infer(language,text,speaker_id, n_scale= 0.667,n_scale_w = 0.8, l_scale = 1
130
  final_list = extrac(text.replace('“','').replace('”',''))
131
  audio_fin = []
132
  c = 0
 
 
133
  for sentence in final_list:
134
  c +=1
135
- try:
136
- stn_tst = get_text(sle(language,sentence), hps_ms)
137
- with torch.no_grad():
138
- x_tst = stn_tst.unsqueeze(0).to(dev)
139
- x_tst_lengths = torch.LongTensor([stn_tst.size(0)]).to(dev)
140
- sid = torch.LongTensor([speaker_id]).to(dev)
141
- t1 = time.time()
142
- audio = net_g_ms.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=n_scale, noise_scale_w=n_scale_w, length_scale=l_scale)[0][0,0].data.cpu().float().numpy()
143
- t2 = time.time()
144
- spending_time = "第"+str(c)+"句的推理时间为:"+str(t2-t1)+"s"
145
- print(spending_time)
146
- audio_fin.append(audio)
147
- except:
148
- print('存在非法字符')
 
 
 
149
  return (hps_ms.data.sampling_rate, np.concatenate(audio_fin))
150
  lan = ["中文","日文","自动"]
151
  idols = ["高咲侑","歩夢","かすみ","しずく","果林","愛","せつ菜","璃奈","栞子","エマ","ランジュ","ミア","派蒙"]
@@ -171,7 +176,7 @@ with app:
171
  para_input3 = gr.Slider(minimum= 0.1,maximum=10,label="更改时间比例", value=1)
172
  tts_submit = gr.Button("Generate", variant="primary")
173
  speaker1 = gr.Dropdown(label="选择说话人",choices=idols, value="歩夢", interactive=True)
174
- tts_output2 = gr.Audio(label="Output")
175
  tts_submit.click(infer, [language,tts_input1,speaker1,para_input1,para_input2,para_input3], [tts_output2])
176
  #app.launch(share=True)
177
  app.launch()
 
130
  final_list = extrac(text.replace('“','').replace('”',''))
131
  audio_fin = []
132
  c = 0
133
+ t = datetime.timedelta(seconds=0)
134
+ f1 = open("lovelive/subtitles.srt",'w',encoding='utf-8')
135
  for sentence in final_list:
136
  c +=1
137
+ stn_tst = get_text(sle(language,sentence), hps_ms)
138
+ with torch.no_grad():
139
+ x_tst = stn_tst.unsqueeze(0).to(dev)
140
+ x_tst_lengths = torch.LongTensor([stn_tst.size(0)]).to(dev)
141
+ sid = torch.LongTensor([speaker_id]).to(dev)
142
+ t1 = time.time()
143
+ audio = net_g_ms.infer(x_tst, x_tst_lengths, sid=sid, noise_scale=n_scale, noise_scale_w=n_scale_w, length_scale=l_scale)[0][0,0].data.cpu().float().numpy()
144
+ t2 = time.time()
145
+ spending_time = "第"+str(c)+"句的推理时间为:"+str(t2-t1)+"s"
146
+ print(spending_time)
147
+ time_start = str(t).split(".")[0] + "," + str(t.microseconds)[:3]
148
+ last_time = datetime.timedelta(seconds=len(audio)/float(22050))
149
+ t+=last_time
150
+ time_end = str(t).split(".")[0] + "," + str(t.microseconds)[:3]
151
+ print(time_end)
152
+ f1.write(str(c-1)+'\n'+time_start+' --> '+time_end+'\n'+sentence+'\n\n')
153
+ audio_fin.append(audio)
154
  return (hps_ms.data.sampling_rate, np.concatenate(audio_fin))
155
  lan = ["中文","日文","自动"]
156
  idols = ["高咲侑","歩夢","かすみ","しずく","果林","愛","せつ菜","璃奈","栞子","エマ","ランジュ","ミア","派蒙"]
 
176
  para_input3 = gr.Slider(minimum= 0.1,maximum=10,label="更改时间比例", value=1)
177
  tts_submit = gr.Button("Generate", variant="primary")
178
  speaker1 = gr.Dropdown(label="选择说话人",choices=idols, value="歩夢", interactive=True)
179
+ tts_output2 = gr.Audio(label="字幕见 https://huggingface.co/spaces/Mahiruoshi/Lovelive_Nijigasaki_VITS/lovelive/subtitles.srt")
180
  tts_submit.click(infer, [language,tts_input1,speaker1,para_input1,para_input2,para_input3], [tts_output2])
181
  #app.launch(share=True)
182
  app.launch()