Mahiruoshi commited on
Commit
0a755d3
1 Parent(s): 1a8c404

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -18
app.py CHANGED
@@ -195,24 +195,27 @@ def create_tts_fn(net_g,hps,speaker_id):
195
  t = datetime.timedelta(seconds=0)
196
  f1 = open("subtitles.srt",'w',encoding='utf-8')
197
  for sentence in final_list:
198
- c +=1
199
- stn_tst = get_text(sle(language,sentence),hps)
200
- with torch.no_grad():
201
- x_tst = stn_tst.unsqueeze(0).to(dev)
202
- x_tst_lengths = torch.LongTensor([stn_tst.size(0)]).to(dev)
203
- sid = torch.LongTensor([speaker_id]).to(dev)
204
- t1 = time.time()
205
- audio = net_g.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()
206
- t2 = time.time()
207
- spending_time = "第"+str(c)+"句的推理时间为:"+str(t2-t1)+"s"
208
- print(spending_time)
209
- time_start = str(t).split(".")[0] + "," + str(t.microseconds)[:3]
210
- last_time = datetime.timedelta(seconds=len(audio)/float(22050))
211
- t+=last_time
212
- time_end = str(t).split(".")[0] + "," + str(t.microseconds)[:3]
213
- print(time_end)
214
- f1.write(str(c-1)+'\n'+time_start+' --> '+time_end+'\n'+sentence+'\n\n')
215
- audio_fin.append(audio)
 
 
 
216
  try:
217
  write(audiopath + '.wav',22050,np.concatenate(audio_fin))
218
  if is_audio:
 
195
  t = datetime.timedelta(seconds=0)
196
  f1 = open("subtitles.srt",'w',encoding='utf-8')
197
  for sentence in final_list:
198
+ try:
199
+ c +=1
200
+ stn_tst = get_text(sle(language,sentence),hps)
201
+ with torch.no_grad():
202
+ x_tst = stn_tst.unsqueeze(0).to(dev)
203
+ x_tst_lengths = torch.LongTensor([stn_tst.size(0)]).to(dev)
204
+ sid = torch.LongTensor([speaker_id]).to(dev)
205
+ t1 = time.time()
206
+ audio = net_g.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()
207
+ t2 = time.time()
208
+ spending_time = "第"+str(c)+"句的推理时间为:"+str(t2-t1)+"s"
209
+ print(spending_time)
210
+ time_start = str(t).split(".")[0] + "," + str(t.microseconds)[:3]
211
+ last_time = datetime.timedelta(seconds=len(audio)/float(22050))
212
+ t+=last_time
213
+ time_end = str(t).split(".")[0] + "," + str(t.microseconds)[:3]
214
+ print(time_end)
215
+ f1.write(str(c-1)+'\n'+time_start+' --> '+time_end+'\n'+sentence+'\n\n')
216
+ audio_fin.append(audio)
217
+ except:
218
+ pass
219
  try:
220
  write(audiopath + '.wav',22050,np.concatenate(audio_fin))
221
  if is_audio: