forked from RVC-Boss/GPT-SoVITS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebui.py
1338 lines (1257 loc) · 50.5 KB
/
webui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json, yaml, warnings, torch
import platform
warnings.filterwarnings("ignore")
torch.manual_seed(233333)
import os, sys
now_dir = os.getcwd()
tmp = os.path.join(now_dir, "TEMP")
os.makedirs(tmp, exist_ok=True)
os.environ["TEMP"] = tmp
import site
site_packages_root = "%s/runtime/Lib/site-packages" % now_dir
for path in site.getsitepackages():
if "site-packages" in path:
site_packages_root = path
os.environ["OPENBLAS_NUM_THREADS"] = "4"
os.environ["no_proxy"] = "localhost, 127.0.0.1, ::1"
with open("%s/users.pth" % (site_packages_root), "w") as f:
f.write(
"%s\n%s/tools\n%s/tools/damo_asr\n%s/GPT_SoVITS\n%s/tools/uvr5"
% (now_dir, now_dir, now_dir, now_dir, now_dir)
)
import traceback
sys.path.append(now_dir)
import gradio as gr
from subprocess import Popen
from config import (
python_exec,
infer_device,
is_half,
exp_root,
webui_port_main,
webui_port_infer_tts,
webui_port_uvr5,
webui_port_subfix,
)
from tools.i18n.i18n import I18nAuto
i18n = I18nAuto()
from multiprocessing import cpu_count
n_cpu = cpu_count()
# 判断是否有能用来训练和加速推理的N卡
ngpu = torch.cuda.device_count()
gpu_infos = []
mem = []
if_gpu_ok = False
if torch.cuda.is_available() or ngpu != 0:
for i in range(ngpu):
gpu_name = torch.cuda.get_device_name(i)
if any(
value in gpu_name.upper()
for value in [
"10",
"16",
"20",
"30",
"40",
"A2",
"A3",
"A4",
"P4",
"A50",
"500",
"A60",
"70",
"80",
"90",
"M4",
"T4",
"TITAN",
"L",
]
):
# A10#A100#V100#A40#P40#M40#K80#A4500
if_gpu_ok = True # 至少有一张能用的N卡
gpu_infos.append("%s\t%s" % (i, gpu_name))
mem.append(
int(
torch.cuda.get_device_properties(i).total_memory
/ 1024
/ 1024
/ 1024
+ 0.4
)
)
if if_gpu_ok and len(gpu_infos) > 0:
gpu_info = "\n".join(gpu_infos)
default_batch_size = min(mem) // 2
else:
gpu_info = i18n("很遗憾您这没有能用的显卡来支持您训练")
default_batch_size = 1
gpus = "-".join([i[0] for i in gpu_infos])
pretrained_sovits_name = "GPT_SoVITS/pretrained_models/s2G488k.pth"
pretrained_gpt_name = (
"GPT_SoVITS/pretrained_models/s1bert25hz-2kh-longer-epoch=68e-step=50232.ckpt"
)
def get_weights_names():
SoVITS_names = [pretrained_sovits_name]
for name in os.listdir(SoVITS_weight_root):
if name.endswith(".pth"):
SoVITS_names.append(name)
GPT_names = [pretrained_gpt_name]
for name in os.listdir(GPT_weight_root):
if name.endswith(".ckpt"):
GPT_names.append(name)
return SoVITS_names, GPT_names
SoVITS_weight_root = "SoVITS_weights"
GPT_weight_root = "GPT_weights"
os.makedirs(SoVITS_weight_root, exist_ok=True)
os.makedirs(GPT_weight_root, exist_ok=True)
SoVITS_names, GPT_names = get_weights_names()
def change_choices():
SoVITS_names, GPT_names = get_weights_names()
return {"choices": sorted(SoVITS_names), "__type__": "update"}, {
"choices": sorted(GPT_names),
"__type__": "update",
}
p_label = None
p_uvr5 = None
p_asr = None
p_tts_inference = None
system = platform.system()
def kill_process(pid):
if system == "Windows":
cmd = "taskkill /t /f /pid %s" % pid
else:
cmd = "kill -9 %s" % pid
print(cmd)
os.system(cmd) ###linux上杀了webui,可能还会没杀干净。。。
# os.kill(p_label.pid,19)#主进程#控制台进程#python子进程###不好使,连主进程的webui一起关了,辣鸡
def change_label(if_label, path_list):
global p_label
if if_label == True and p_label == None:
cmd = '"%s" tools/subfix_webui.py --load_list "%s" --webui_port %s' % (
python_exec,
path_list,
webui_port_subfix,
)
yield "打标工具WebUI已开启"
print(cmd)
p_label = Popen(cmd, shell=True)
elif if_label == False and p_label != None:
kill_process(p_label.pid)
p_label = None
yield "打标工具WebUI已关闭"
def change_uvr5(if_uvr5):
global p_uvr5
if if_uvr5 == True and p_uvr5 == None:
cmd = '"%s" tools/uvr5/webui.py "%s" %s %s' % (
python_exec,
infer_device,
is_half,
webui_port_uvr5,
)
yield "UVR5已开启"
print(cmd)
p_uvr5 = Popen(cmd, shell=True)
elif if_uvr5 == False and p_uvr5 != None:
kill_process(p_uvr5.pid)
p_uvr5 = None
yield "UVR5已关闭"
def change_tts_inference(
if_tts, bert_path, cnhubert_base_path, gpu_number, gpt_path, sovits_path
):
global p_tts_inference
if if_tts == True and p_tts_inference == None:
os.environ["gpt_path"] = (
gpt_path if "/" in gpt_path else "%s/%s" % (GPT_weight_root, gpt_path)
)
os.environ["sovits_path"] = (
sovits_path
if "/" in sovits_path
else "%s/%s" % (SoVITS_weight_root, sovits_path)
)
os.environ["cnhubert_base_path"] = cnhubert_base_path
os.environ["bert_path"] = bert_path
os.environ["_CUDA_VISIBLE_DEVICES"] = gpu_number
os.environ["is_half"] = str(is_half)
os.environ["infer_ttswebui"] = str(webui_port_infer_tts)
cmd = '"%s" GPT_SoVITS/inference_webui.py' % (python_exec)
yield "TTS推理进程已开启"
print(cmd)
p_tts_inference = Popen(cmd, shell=True)
elif if_tts == False and p_tts_inference != None:
kill_process(p_tts_inference.pid)
p_tts_inference = None
yield "TTS推理进程已关闭"
def open_asr(asr_inp_dir):
global p_asr
if p_asr == None:
cmd = '"%s" tools/damo_asr/cmd-asr.py "%s"' % (python_exec, asr_inp_dir)
yield "ASR任务开启:%s" % cmd, {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
print(cmd)
p_asr = Popen(cmd, shell=True)
p_asr.wait()
p_asr = None
yield "ASR任务完成", {"__type__": "update", "visible": True}, {
"__type__": "update",
"visible": False,
}
else:
yield "已有正在进行的ASR任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
def close_asr():
global p_asr
if p_asr != None:
kill_process(p_asr.pid)
p_asr = None
return (
"已终止ASR进程",
{"__type__": "update", "visible": True},
{"__type__": "update", "visible": False},
)
"""
button1Ba_open.click(open1Ba, [batch_size,total_epoch,exp_name,text_low_lr_rate,if_save_latest,if_save_every_weights,gpu_numbers1Ba,pretrained_s2G,pretrained_s2D], [info1Bb,button1Ba_open,button1Ba_close])
button1Ba_close.click(close1Ba, [], [info1Bb,button1Ba_open,button1Ba_close])
"""
p_train_SoVITS = None
def open1Ba(
batch_size,
total_epoch,
exp_name,
text_low_lr_rate,
if_save_latest,
if_save_every_weights,
save_every_epoch,
gpu_numbers1Ba,
pretrained_s2G,
pretrained_s2D,
):
global p_train_SoVITS
if p_train_SoVITS == None:
with open("GPT_SoVITS/configs/s2.json") as f:
data = f.read()
data = json.loads(data)
s2_dir = "%s/%s" % (exp_root, exp_name)
os.makedirs("%s/logs_s2" % (s2_dir), exist_ok=True)
data["train"]["batch_size"] = batch_size
data["train"]["epochs"] = total_epoch
data["train"]["text_low_lr_rate"] = text_low_lr_rate
data["train"]["pretrained_s2G"] = pretrained_s2G
data["train"]["pretrained_s2D"] = pretrained_s2D
data["train"]["if_save_latest"] = if_save_latest
data["train"]["if_save_every_weights"] = if_save_every_weights
data["train"]["save_every_epoch"] = save_every_epoch
data["train"]["gpu_numbers"] = gpu_numbers1Ba
data["data"]["exp_dir"] = data["s2_ckpt_dir"] = s2_dir
data["save_weight_dir"] = SoVITS_weight_root
data["name"] = exp_name
tmp_config_path = "TEMP/tmp_s2.json"
with open(tmp_config_path, "w") as f:
f.write(json.dumps(data))
cmd = '"%s" GPT_SoVITS/s2_train.py --config "%s"' % (
python_exec,
tmp_config_path,
)
yield "SoVITS训练开始:%s" % cmd, {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
print(cmd)
p_train_SoVITS = Popen(cmd, shell=True)
p_train_SoVITS.wait()
p_train_SoVITS = None
yield "SoVITS训练完成", {"__type__": "update", "visible": True}, {
"__type__": "update",
"visible": False,
}
else:
yield "已有正在进行的SoVITS训练任务,需先终止才能开启下一次任务", {
"__type__": "update",
"visible": False,
}, {"__type__": "update", "visible": True}
def close1Ba():
global p_train_SoVITS
if p_train_SoVITS != None:
kill_process(p_train_SoVITS.pid)
p_train_SoVITS = None
return (
"已终止SoVITS训练",
{"__type__": "update", "visible": True},
{"__type__": "update", "visible": False},
)
p_train_GPT = None
def open1Bb(
batch_size,
total_epoch,
exp_name,
if_save_latest,
if_save_every_weights,
save_every_epoch,
gpu_numbers,
pretrained_s1,
):
global p_train_GPT
if p_train_GPT == None:
with open("GPT_SoVITS/configs/s1longer.yaml") as f:
data = f.read()
data = yaml.load(data, Loader=yaml.FullLoader)
s1_dir = "%s/%s" % (exp_root, exp_name)
os.makedirs("%s/logs_s1" % (s1_dir), exist_ok=True)
data["train"]["batch_size"] = batch_size
data["train"]["epochs"] = total_epoch
data["pretrained_s1"] = pretrained_s1
data["train"]["save_every_n_epoch"] = save_every_epoch
data["train"]["if_save_every_weights"] = if_save_every_weights
data["train"]["if_save_latest"] = if_save_latest
data["train"]["half_weights_save_dir"] = GPT_weight_root
data["train"]["exp_name"] = exp_name
data["train_semantic_path"] = "%s/6-name2semantic.tsv" % s1_dir
data["train_phoneme_path"] = "%s/2-name2text.txt" % s1_dir
data["output_dir"] = "%s/logs_s1" % s1_dir
os.environ["_CUDA_VISIBLE_DEVICES"] = gpu_numbers.replace("-", ",")
os.environ["hz"] = "25hz"
tmp_config_path = "TEMP/tmp_s1.yaml"
with open(tmp_config_path, "w") as f:
f.write(yaml.dump(data, default_flow_style=False))
# cmd = '"%s" GPT_SoVITS/s1_train.py --config_file "%s" --train_semantic_path "%s/6-name2semantic.tsv" --train_phoneme_path "%s/2-name2text.txt" --output_dir "%s/logs_s1"'%(python_exec,tmp_config_path,s1_dir,s1_dir,s1_dir)
cmd = '"%s" GPT_SoVITS/s1_train.py --config_file "%s" ' % (
python_exec,
tmp_config_path,
)
yield "GPT训练开始:%s" % cmd, {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
print(cmd)
p_train_GPT = Popen(cmd, shell=True)
p_train_GPT.wait()
p_train_GPT = None
yield "GPT训练完成", {"__type__": "update", "visible": True}, {
"__type__": "update",
"visible": False,
}
else:
yield "已有正在进行的GPT训练任务,需先终止才能开启下一次任务", {
"__type__": "update",
"visible": False,
}, {"__type__": "update", "visible": True}
def close1Bb():
global p_train_GPT
if p_train_GPT != None:
kill_process(p_train_GPT.pid)
p_train_GPT = None
return (
"已终止GPT训练",
{"__type__": "update", "visible": True},
{"__type__": "update", "visible": False},
)
ps_slice = []
def open_slice(
inp,
opt_root,
threshold,
min_length,
min_interval,
hop_size,
max_sil_kept,
_max,
alpha,
n_parts,
):
global ps_slice
if os.path.exists(inp) == False:
yield "输入路径不存在", {"__type__": "update", "visible": True}, {
"__type__": "update",
"visible": False,
}
return
if os.path.isfile(inp):
n_parts = 1
elif os.path.isdir(inp):
pass
else:
yield "输入路径存在但既不是文件也不是文件夹", {"__type__": "update", "visible": True}, {
"__type__": "update",
"visible": False,
}
return
if ps_slice == []:
for i_part in range(n_parts):
cmd = (
'"%s" tools/slice_audio.py "%s" "%s" %s %s %s %s %s %s %s %s %s'
""
% (
python_exec,
inp,
opt_root,
threshold,
min_length,
min_interval,
hop_size,
max_sil_kept,
_max,
alpha,
i_part,
n_parts,
)
)
print(cmd)
p = Popen(cmd, shell=True)
ps_slice.append(p)
yield "切割执行中", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
for p in ps_slice:
p.wait()
ps_slice = []
yield "切割结束", {"__type__": "update", "visible": True}, {
"__type__": "update",
"visible": False,
}
else:
yield "已有正在进行的切割任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
def close_slice():
global ps_slice
if ps_slice != []:
for p_slice in ps_slice:
try:
kill_process(p_slice.pid)
except:
traceback.print_exc()
ps_slice = []
return (
"已终止所有切割进程",
{"__type__": "update", "visible": True},
{"__type__": "update", "visible": False},
)
"""
inp_text= os.environ.get("inp_text")
inp_wav_dir= os.environ.get("inp_wav_dir")
exp_name= os.environ.get("exp_name")
i_part= os.environ.get("i_part")
all_parts= os.environ.get("all_parts")
os.environ["CUDA_VISIBLE_DEVICES"]= os.environ.get("_CUDA_VISIBLE_DEVICES")
opt_dir= os.environ.get("opt_dir")#"/data/docker/liujing04/gpt-vits/fine_tune_dataset/%s"%exp_name
bert_pretrained_dir= os.environ.get("bert_pretrained_dir")#"/data/docker/liujing04/bert-vits2/Bert-VITS2-master20231106/bert/chinese-roberta-wwm-ext-large"
"""
ps1a = []
def open1a(inp_text, inp_wav_dir, exp_name, gpu_numbers, bert_pretrained_dir):
global ps1a
if ps1a == []:
config = {
"inp_text": inp_text,
"inp_wav_dir": inp_wav_dir,
"exp_name": exp_name,
"opt_dir": "%s/%s" % (exp_root, exp_name),
"bert_pretrained_dir": bert_pretrained_dir,
}
gpu_names = gpu_numbers.split("-")
all_parts = len(gpu_names)
for i_part in range(all_parts):
config.update(
{
"i_part": str(i_part),
"all_parts": str(all_parts),
"_CUDA_VISIBLE_DEVICES": gpu_names[i_part],
"is_half": str(is_half),
}
)
os.environ.update(config)
cmd = '"%s" GPT_SoVITS/prepare_datasets/1-get-text.py' % python_exec
print(cmd)
p = Popen(cmd, shell=True)
ps1a.append(p)
yield "文本进程执行中", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
for p in ps1a:
p.wait()
ps1a = []
yield "文本进程结束", {"__type__": "update", "visible": True}, {
"__type__": "update",
"visible": False,
}
else:
yield "已有正在进行的文本任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
def close1a():
global ps1a
if ps1a != []:
for p1a in ps1a:
try:
kill_process(p1a.pid)
except:
traceback.print_exc()
ps1a = []
return (
"已终止所有1a进程",
{"__type__": "update", "visible": True},
{"__type__": "update", "visible": False},
)
"""
inp_text= os.environ.get("inp_text")
inp_wav_dir= os.environ.get("inp_wav_dir")
exp_name= os.environ.get("exp_name")
i_part= os.environ.get("i_part")
all_parts= os.environ.get("all_parts")
os.environ["CUDA_VISIBLE_DEVICES"]= os.environ.get("_CUDA_VISIBLE_DEVICES")
opt_dir= os.environ.get("opt_dir")
cnhubert.cnhubert_base_path= os.environ.get("cnhubert_base_dir")
"""
ps1b = []
def open1b(inp_text, inp_wav_dir, exp_name, gpu_numbers, ssl_pretrained_dir):
global ps1b
if ps1b == []:
config = {
"inp_text": inp_text,
"inp_wav_dir": inp_wav_dir,
"exp_name": exp_name,
"opt_dir": "%s/%s" % (exp_root, exp_name),
"cnhubert_base_dir": ssl_pretrained_dir,
"is_half": str(is_half),
}
gpu_names = gpu_numbers.split("-")
all_parts = len(gpu_names)
for i_part in range(all_parts):
config.update(
{
"i_part": str(i_part),
"all_parts": str(all_parts),
"_CUDA_VISIBLE_DEVICES": gpu_names[i_part],
}
)
os.environ.update(config)
cmd = (
'"%s" GPT_SoVITS/prepare_datasets/2-get-hubert-wav32k.py' % python_exec
)
print(cmd)
p = Popen(cmd, shell=True)
ps1b.append(p)
yield "SSL提取进程执行中", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
for p in ps1b:
p.wait()
ps1b = []
yield "SSL提取进程结束", {"__type__": "update", "visible": True}, {
"__type__": "update",
"visible": False,
}
else:
yield "已有正在进行的SSL提取任务,需先终止才能开启下一次任务", {
"__type__": "update",
"visible": False,
}, {"__type__": "update", "visible": True}
def close1b():
global ps1b
if ps1b != []:
for p1b in ps1b:
try:
kill_process(p1b.pid)
except:
traceback.print_exc()
ps1b = []
return (
"已终止所有1b进程",
{"__type__": "update", "visible": True},
{"__type__": "update", "visible": False},
)
"""
inp_text= os.environ.get("inp_text")
exp_name= os.environ.get("exp_name")
i_part= os.environ.get("i_part")
all_parts= os.environ.get("all_parts")
os.environ["CUDA_VISIBLE_DEVICES"]= os.environ.get("_CUDA_VISIBLE_DEVICES")
opt_dir= os.environ.get("opt_dir")
pretrained_s2G= os.environ.get("pretrained_s2G")
"""
ps1c = []
def open1c(inp_text, exp_name, gpu_numbers, pretrained_s2G_path):
global ps1c
if ps1c == []:
config = {
"inp_text": inp_text,
"exp_name": exp_name,
"opt_dir": "%s/%s" % (exp_root, exp_name),
"pretrained_s2G": pretrained_s2G_path,
"s2config_path": "GPT_SoVITS/configs/s2.json",
"is_half": str(is_half),
}
gpu_names = gpu_numbers.split("-")
all_parts = len(gpu_names)
for i_part in range(all_parts):
config.update(
{
"i_part": str(i_part),
"all_parts": str(all_parts),
"_CUDA_VISIBLE_DEVICES": gpu_names[i_part],
}
)
os.environ.update(config)
cmd = '"%s" GPT_SoVITS/prepare_datasets/3-get-semantic.py' % python_exec
print(cmd)
p = Popen(cmd, shell=True)
ps1c.append(p)
yield "语义token提取进程执行中", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
for p in ps1c:
p.wait()
ps1c = []
yield "语义token提取进程结束", {"__type__": "update", "visible": True}, {
"__type__": "update",
"visible": False,
}
else:
yield "已有正在进行的语义token提取任务,需先终止才能开启下一次任务", {
"__type__": "update",
"visible": False,
}, {"__type__": "update", "visible": True}
def close1c():
global ps1c
if ps1c != []:
for p1c in ps1c:
try:
kill_process(p1c.pid)
except:
traceback.print_exc()
ps1c = []
return (
"已终止所有语义token进程",
{"__type__": "update", "visible": True},
{"__type__": "update", "visible": False},
)
#####inp_text,inp_wav_dir,exp_name,gpu_numbers1a,gpu_numbers1Ba,gpu_numbers1c,bert_pretrained_dir,cnhubert_base_dir,pretrained_s2G
ps1abc = []
def open1abc(
inp_text,
inp_wav_dir,
exp_name,
gpu_numbers1a,
gpu_numbers1Ba,
gpu_numbers1c,
bert_pretrained_dir,
ssl_pretrained_dir,
pretrained_s2G_path,
):
global ps1abc
if ps1abc == []:
opt_dir = "%s/%s" % (exp_root, exp_name)
try:
#############################1a
path_text = "%s/2-name2text.txt" % opt_dir
if os.path.exists(path_text) == False:
config = {
"inp_text": inp_text,
"inp_wav_dir": inp_wav_dir,
"exp_name": exp_name,
"opt_dir": opt_dir,
"bert_pretrained_dir": bert_pretrained_dir,
"is_half": str(is_half),
}
gpu_names = gpu_numbers1a.split("-")
all_parts = len(gpu_names)
for i_part in range(all_parts):
config.update(
{
"i_part": str(i_part),
"all_parts": str(all_parts),
"_CUDA_VISIBLE_DEVICES": gpu_names[i_part],
}
)
os.environ.update(config)
cmd = '"%s" GPT_SoVITS/prepare_datasets/1-get-text.py' % python_exec
print(cmd)
p = Popen(cmd, shell=True)
ps1abc.append(p)
yield "进度:1a-ing", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
for p in ps1abc:
p.wait()
opt = []
for i_part in range(
all_parts
): # txt_path="%s/2-name2text-%s.txt"%(opt_dir,i_part)
txt_path = "%s/2-name2text-%s.txt" % (opt_dir, i_part)
with open(txt_path, "r", encoding="utf8") as f:
opt += f.read().strip("\n").split("\n")
os.remove(txt_path)
with open(path_text, "w", encoding="utf8") as f:
f.write("\n".join(opt) + "\n")
yield "进度:1a-done", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
ps1abc = []
#############################1b
config = {
"inp_text": inp_text,
"inp_wav_dir": inp_wav_dir,
"exp_name": exp_name,
"opt_dir": opt_dir,
"cnhubert_base_dir": ssl_pretrained_dir,
}
gpu_names = gpu_numbers1Ba.split("-")
all_parts = len(gpu_names)
for i_part in range(all_parts):
config.update(
{
"i_part": str(i_part),
"all_parts": str(all_parts),
"_CUDA_VISIBLE_DEVICES": gpu_names[i_part],
}
)
os.environ.update(config)
cmd = (
'"%s" GPT_SoVITS/prepare_datasets/2-get-hubert-wav32k.py'
% python_exec
)
print(cmd)
p = Popen(cmd, shell=True)
ps1abc.append(p)
yield "进度:1a-done, 1b-ing", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
for p in ps1abc:
p.wait()
yield "进度:1a1b-done", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
ps1abc = []
#############################1c
path_semantic = "%s/6-name2semantic.tsv" % opt_dir
if os.path.exists(path_semantic) == False:
config = {
"inp_text": inp_text,
"exp_name": exp_name,
"opt_dir": opt_dir,
"pretrained_s2G": pretrained_s2G_path,
"s2config_path": "GPT_SoVITS/configs/s2.json",
}
gpu_names = gpu_numbers1c.split("-")
all_parts = len(gpu_names)
for i_part in range(all_parts):
config.update(
{
"i_part": str(i_part),
"all_parts": str(all_parts),
"_CUDA_VISIBLE_DEVICES": gpu_names[i_part],
}
)
os.environ.update(config)
cmd = (
'"%s" GPT_SoVITS/prepare_datasets/3-get-semantic.py'
% python_exec
)
print(cmd)
p = Popen(cmd, shell=True)
ps1abc.append(p)
yield "进度:1a1b-done, 1cing", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
for p in ps1abc:
p.wait()
opt = ["item_name semantic_audio"]
for i_part in range(all_parts):
semantic_path = "%s/6-name2semantic-%s.tsv" % (opt_dir, i_part)
with open(semantic_path, "r", encoding="utf8") as f:
opt += f.read().strip("\n").split("\n")
os.remove(semantic_path)
with open(path_semantic, "w", encoding="utf8") as f:
f.write("\n".join(opt) + "\n")
yield "进度:all-done", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
ps1abc = []
yield "一键三连进程结束", {"__type__": "update", "visible": True}, {
"__type__": "update",
"visible": False,
}
except:
traceback.print_exc()
close1abc()
yield "一键三连中途报错", {"__type__": "update", "visible": True}, {
"__type__": "update",
"visible": False,
}
else:
yield "已有正在进行的一键三连任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {
"__type__": "update",
"visible": True,
}
def close1abc():
global ps1abc
if ps1abc != []:
for p1abc in ps1abc:
try:
kill_process(p1abc.pid)
except:
traceback.print_exc()
ps1abc = []
return (
"已终止所有一键三连进程",
{"__type__": "update", "visible": True},
{"__type__": "update", "visible": False},
)
with gr.Blocks(title="GPT-SoVITS WebUI") as app:
gr.Markdown(
value="本软件以MIT协议开源, 作者不对软件具备任何控制力, 使用软件者、传播软件导出的声音者自负全责. <br>如不认可该条款, 则不能使用或引用软件包内任何代码和文件. 详见根目录<b>LICENSE</b>."
)
with gr.Tabs():
with gr.TabItem("0-前置数据集获取工具"): # 提前随机切片防止uvr5爆内存->uvr5->slicer->asr->打标
gr.Markdown(value="0a-UVR5人声伴奏分离&去混响去延迟工具")
with gr.Row():
if_uvr5 = gr.Checkbox(label="是否开启UVR5-WebUI", show_label=True)
uvr5_info = gr.Textbox(label="UVR5进程输出信息")
gr.Markdown(value="0b-语音切分工具")
with gr.Row():
with gr.Row():
slice_inp_path = gr.Textbox(label="音频自动切分输入路径,可文件可文件夹", value="")
slice_opt_root = gr.Textbox(
label="切分后的子音频的输出根目录", value="output/slicer_opt"
)
threshold = gr.Textbox(
label="threshold:音量小于这个值视作静音的备选切割点", value="-34"
)
min_length = gr.Textbox(
label="min_length:每段最小多长,如果第一段太短一直和后面段连起来直到超过这个值", value="4000"
)
min_interval = gr.Textbox(label="min_interval:最短切割间隔", value="300")
hop_size = gr.Textbox(
label="hop_size:怎么算音量曲线,越小精度越大计算量越高(不是精度越大效果越好)", value="10"
)
max_sil_kept = gr.Textbox(
label="max_sil_kept:切完后静音最多留多长", value="500"
)
with gr.Row():
open_slicer_button = gr.Button(
"开启语音切割", variant="primary", visible=True
)
close_slicer_button = gr.Button(
"终止语音切割", variant="primary", visible=False
)
_max = gr.Slider(
minimum=0,
maximum=1,
step=0.05,
label="max:归一化后最大值多少",
value=0.9,
interactive=True,
)
alpha = gr.Slider(
minimum=0,
maximum=1,
step=0.05,
label="alpha_mix:混多少比例归一化后音频进来",
value=0.25,
interactive=True,
)
n_process = gr.Slider(
minimum=1,
maximum=n_cpu,
step=1,
label="切割使用的进程数",
value=4,
interactive=True,
)
slicer_info = gr.Textbox(label="语音切割进程输出信息")
gr.Markdown(value="0c-中文批量离线ASR工具")
with gr.Row():
open_asr_button = gr.Button(
"开启离线批量ASR", variant="primary", visible=True
)
close_asr_button = gr.Button(
"终止ASR进程", variant="primary", visible=False
)
asr_inp_dir = gr.Textbox(
label="批量ASR(中文only)输入文件夹路径",
value="D:\\RVC1006\\GPT-SoVITS\\raw\\xxx",
interactive=True,
)
asr_info = gr.Textbox(label="ASR进程输出信息")
gr.Markdown(value="0d-语音文本校对标注工具")
with gr.Row():
if_label = gr.Checkbox(label="是否开启打标WebUI", show_label=True)
path_list = gr.Textbox(
label="打标数据标注文件路径",
value="D:\\RVC1006\\GPT-SoVITS\\raw\\xxx.list",
interactive=True,
)
label_info = gr.Textbox(label="打标工具进程输出信息")
if_label.change(change_label, [if_label, path_list], [label_info])
if_uvr5.change(change_uvr5, [if_uvr5], [uvr5_info])
open_asr_button.click(
open_asr, [asr_inp_dir], [asr_info, open_asr_button, close_asr_button]
)
close_asr_button.click(
close_asr, [], [asr_info, open_asr_button, close_asr_button]
)
open_slicer_button.click(
open_slice,
[
slice_inp_path,
slice_opt_root,
threshold,
min_length,
min_interval,
hop_size,
max_sil_kept,
_max,
alpha,
n_process,