rmysmo commited on
Commit
6e75975
1 Parent(s): 790ebde

added translate

Browse files
Files changed (2) hide show
  1. app.py +415 -361
  2. i18n/uz_UZ.json +2 -2
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import subprocess, torch, os, traceback, sys, warnings, shutil, numpy as np
2
  from mega import Mega
 
3
  os.environ["no_proxy"] = "localhost, 127.0.0.1, ::1"
4
  import threading
5
  from time import sleep
@@ -8,6 +9,7 @@ import faiss
8
  from random import shuffle
9
  import json, datetime, requests
10
  from gtts import gTTS
 
11
  now_dir = os.getcwd()
12
  sys.path.append(now_dir)
13
  tmp = os.path.join(now_dir, "TEMP")
@@ -38,12 +40,14 @@ if not os.path.isdir('csvdb/'):
38
  try:
39
  DoFormant, Quefrency, Timbre = CSVutil('csvdb/formanting.csv', 'r', 'formanting')
40
  DoFormant = (
41
- lambda DoFormant: True if DoFormant.lower() == 'true' else (False if DoFormant.lower() == 'false' else DoFormant)
 
42
  )(DoFormant)
43
  except (ValueError, TypeError, IndexError):
44
  DoFormant, Quefrency, Timbre = False, 1.0, 1.0
45
  CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, Quefrency, Timbre)
46
 
 
47
  def download_models():
48
  # Download hubert base model if not present
49
  if not os.path.isfile('./hubert_base.pt'):
@@ -54,11 +58,13 @@ def download_models():
54
  f.write(response.content)
55
  print("Downloaded hubert base model file successfully. File saved to ./hubert_base.pt.")
56
  else:
57
- raise Exception("Failed to download hubert base model file. Status code: " + str(response.status_code) + ".")
58
-
 
59
  # Download rmvpe model if not present
60
  if not os.path.isfile('./rmvpe.pt'):
61
- response = requests.get('https://drive.usercontent.google.com/download?id=1Hkn4kNuVFRCNQwyxQFRtmzmMBGpQxptI&export=download&authuser=0&confirm=t&uuid=0b3a40de-465b-4c65-8c41-135b0b45c3f7&at=APZUnTV3lA3LnyTbeuduura6Dmi2:1693724254058')
 
62
 
63
  if response.status_code == 200:
64
  with open('./rmvpe.pt', 'wb') as f:
@@ -67,40 +73,41 @@ def download_models():
67
  else:
68
  raise Exception("Failed to download rmvpe model file. Status code: " + str(response.status_code) + ".")
69
 
 
70
  download_models()
71
 
72
  print("\n-------------------------------\nRVC v2 Easy GUI (Local Edition)\n-------------------------------\n")
73
 
 
74
  def formant_apply(qfrency, tmbre):
75
  Quefrency = qfrency
76
  Timbre = tmbre
77
  DoFormant = True
78
  CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, qfrency, tmbre)
79
-
80
  return ({"value": Quefrency, "__type__": "update"}, {"value": Timbre, "__type__": "update"})
81
 
 
82
  def get_fshift_presets():
83
  fshift_presets_list = []
84
  for dirpath, _, filenames in os.walk("./formantshiftcfg/"):
85
  for filename in filenames:
86
  if filename.endswith(".txt"):
87
- fshift_presets_list.append(os.path.join(dirpath,filename).replace('\\','/'))
88
-
89
  if len(fshift_presets_list) > 0:
90
  return fshift_presets_list
91
  else:
92
  return ''
93
 
94
 
95
-
96
  def formant_enabled(cbox, qfrency, tmbre, frmntapply, formantpreset, formant_refresh_button):
97
-
98
  if (cbox):
99
 
100
  DoFormant = True
101
  CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, qfrency, tmbre)
102
- #print(f"is checked? - {cbox}\ngot {DoFormant}")
103
-
104
  return (
105
  {"value": True, "__type__": "update"},
106
  {"visible": True, "__type__": "update"},
@@ -109,14 +116,14 @@ def formant_enabled(cbox, qfrency, tmbre, frmntapply, formantpreset, formant_ref
109
  {"visible": True, "__type__": "update"},
110
  {"visible": True, "__type__": "update"},
111
  )
112
-
113
-
114
  else:
115
-
116
  DoFormant = False
117
  CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, qfrency, tmbre)
118
-
119
- #print(f"is checked? - {cbox}\ngot {DoFormant}")
120
  return (
121
  {"value": False, "__type__": "update"},
122
  {"visible": False, "__type__": "update"},
@@ -126,7 +133,6 @@ def formant_enabled(cbox, qfrency, tmbre, frmntapply, formantpreset, formant_ref
126
  {"visible": False, "__type__": "update"},
127
  {"visible": False, "__type__": "update"},
128
  )
129
-
130
 
131
 
132
  def preset_apply(preset, qfer, tmbr):
@@ -134,21 +140,21 @@ def preset_apply(preset, qfer, tmbr):
134
  with open(str(preset), 'r') as p:
135
  content = p.readlines()
136
  qfer, tmbr = content[0].split('\n')[0], content[1]
137
-
138
  formant_apply(qfer, tmbr)
139
  else:
140
  pass
141
  return ({"value": qfer, "__type__": "update"}, {"value": tmbr, "__type__": "update"})
142
 
 
143
  def update_fshift_presets(preset, qfrency, tmbre):
144
-
145
  qfrency, tmbre = preset_apply(preset, qfrency, tmbre)
146
-
147
  if (str(preset) != ''):
148
  with open(str(preset), 'r') as p:
149
  content = p.readlines()
150
  qfrency, tmbre = content[0].split('\n')[0], content[1]
151
-
152
  formant_apply(qfrency, tmbre)
153
  else:
154
  pass
@@ -158,8 +164,9 @@ def update_fshift_presets(preset, qfrency, tmbre):
158
  {"value": tmbre, "__type__": "update"},
159
  )
160
 
 
161
  i18n = I18nAuto()
162
- #i18n.print()
163
  # 判断是否有能用来训练和加速推理的N卡
164
  ngpu = torch.cuda.device_count()
165
  gpu_infos = []
@@ -171,23 +178,23 @@ else:
171
  for i in range(ngpu):
172
  gpu_name = torch.cuda.get_device_name(i)
173
  if (
174
- "10" in gpu_name
175
- or "16" in gpu_name
176
- or "20" in gpu_name
177
- or "30" in gpu_name
178
- or "40" in gpu_name
179
- or "A2" in gpu_name.upper()
180
- or "A3" in gpu_name.upper()
181
- or "A4" in gpu_name.upper()
182
- or "P4" in gpu_name.upper()
183
- or "A50" in gpu_name.upper()
184
- or "A60" in gpu_name.upper()
185
- or "70" in gpu_name
186
- or "80" in gpu_name
187
- or "90" in gpu_name
188
- or "M4" in gpu_name.upper()
189
- or "T4" in gpu_name.upper()
190
- or "TITAN" in gpu_name.upper()
191
  ): # A10#A100#V100#A40#P40#M40#K80#A4500
192
  if_gpu_ok = True # 至少有一张能用的N卡
193
  gpu_infos.append("%s\t%s" % (i, gpu_name))
@@ -226,6 +233,7 @@ logging.getLogger("numba").setLevel(logging.WARNING)
226
 
227
  hubert_model = None
228
 
 
229
  def load_hubert():
230
  global hubert_model
231
  models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
@@ -254,22 +262,21 @@ for root, dirs, files in os.walk(index_root, topdown=False):
254
  index_paths.append("%s/%s" % (root, name))
255
 
256
 
257
-
258
  def vc_single(
259
- sid,
260
- input_audio_path,
261
- f0_up_key,
262
- f0_file,
263
- f0_method,
264
- file_index,
265
- #file_index2,
266
- # file_big_npy,
267
- index_rate,
268
- filter_radius,
269
- resample_sr,
270
- rms_mix_rate,
271
- protect,
272
- crepe_hop_length,
273
  ): # spk_item, input_audio0, vc_transform0,f0_file,f0method0
274
  global tgt_sr, net_g, vc, hubert_model, version
275
  if input_audio_path is None:
@@ -339,22 +346,22 @@ def vc_single(
339
 
340
 
341
  def vc_multi(
342
- sid,
343
- dir_path,
344
- opt_root,
345
- paths,
346
- f0_up_key,
347
- f0_method,
348
- file_index,
349
- file_index2,
350
- # file_big_npy,
351
- index_rate,
352
- filter_radius,
353
- resample_sr,
354
- rms_mix_rate,
355
- protect,
356
- format1,
357
- crepe_hop_length,
358
  ):
359
  try:
360
  dir_path = (
@@ -416,6 +423,7 @@ def vc_multi(
416
  except:
417
  yield traceback.format_exc()
418
 
 
419
  # 一个选项卡全局只能有一个音色
420
  def get_vc(sid):
421
  global n_spk, tgt_sr, net_g, vc, cpt, version
@@ -535,10 +543,10 @@ def preprocess_dataset(trainset_dir, exp_dir, sr, n_p):
535
  f = open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "w")
536
  f.close()
537
  cmd = (
538
- config.python_cmd
539
- + " trainset_preprocess_pipeline_print.py %s %s %s %s/logs/%s "
540
- % (trainset_dir, sr, n_p, now_dir, exp_dir)
541
- + str(config.noparallel)
542
  )
543
  print(cmd)
544
  p = Popen(cmd, shell=True) # , stdin=PIPE, stdout=PIPE,stderr=PIPE,cwd=now_dir
@@ -562,6 +570,7 @@ def preprocess_dataset(trainset_dir, exp_dir, sr, n_p):
562
  print(log)
563
  yield log
564
 
 
565
  # but2.click(extract_f0,[gpus6,np7,f0method8,if_f0_3,trainset_dir4],[info2])
566
  def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, echl):
567
  gpus = gpus.split("-")
@@ -589,7 +598,7 @@ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, echl):
589
  ).start()
590
  while 1:
591
  with open(
592
- "%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r"
593
  ) as f:
594
  yield (f.read())
595
  sleep(1)
@@ -611,17 +620,17 @@ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, echl):
611
  ps = []
612
  for idx, n_g in enumerate(gpus):
613
  cmd = (
614
- config.python_cmd
615
- + " extract_feature_print.py %s %s %s %s %s/logs/%s %s"
616
- % (
617
- config.device,
618
- leng,
619
- idx,
620
- n_g,
621
- now_dir,
622
- exp_dir,
623
- version19,
624
- )
625
  )
626
  print(cmd)
627
  p = Popen(
@@ -664,6 +673,7 @@ def change_sr2(sr2, if_f0_3, version19):
664
  {"visible": True, "__type__": "update"}
665
  )
666
 
 
667
  def change_version19(sr2, if_f0_3, version19):
668
  path_str = "" if version19 == "v1" else "_v2"
669
  f0_str = "f0" if if_f0_3 else ""
@@ -717,22 +727,23 @@ def set_log_interval(exp_dir, batch_size12):
717
  log_interval += 1
718
  return log_interval
719
 
 
720
  # but3.click(click_train,[exp_dir1,sr2,if_f0_3,save_epoch10,total_epoch11,batch_size12,if_save_latest13,pretrained_G14,pretrained_D15,gpus16])
721
  def click_train(
722
- exp_dir1,
723
- sr2,
724
- if_f0_3,
725
- spk_id5,
726
- save_epoch10,
727
- total_epoch11,
728
- batch_size12,
729
- if_save_latest13,
730
- pretrained_G14,
731
- pretrained_D15,
732
- gpus16,
733
- if_cache_gpu17,
734
- if_save_every_weights18,
735
- version19,
736
  ):
737
  CSVutil('csvdb/stop.csv', 'w+', 'formanting', False)
738
  # 生成filelist
@@ -744,17 +755,17 @@ def click_train(
744
  if version19 == "v1"
745
  else "%s/3_feature768" % (exp_dir)
746
  )
747
-
748
  log_interval = set_log_interval(exp_dir, batch_size12)
749
-
750
  if if_f0_3:
751
  f0_dir = "%s/2a_f0" % (exp_dir)
752
  f0nsf_dir = "%s/2b-f0nsf" % (exp_dir)
753
  names = (
754
- set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)])
755
- & set([name.split(".")[0] for name in os.listdir(feature_dir)])
756
- & set([name.split(".")[0] for name in os.listdir(f0_dir)])
757
- & set([name.split(".")[0] for name in os.listdir(f0nsf_dir)])
758
  )
759
  else:
760
  names = set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)]) & set(
@@ -814,51 +825,52 @@ def click_train(
814
  print("no pretrained Discriminator")
815
  if gpus16:
816
  cmd = (
817
- config.python_cmd
818
- + " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -g %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s -li %s"
819
- % (
820
- exp_dir1,
821
- sr2,
822
- 1 if if_f0_3 else 0,
823
- batch_size12,
824
- gpus16,
825
- total_epoch11,
826
- save_epoch10,
827
- ("-pg %s" % pretrained_G14) if pretrained_G14 != "" else "",
828
- ("-pd %s" % pretrained_D15) if pretrained_D15 != "" else "",
829
- 1 if if_save_latest13 == True else 0,
830
- 1 if if_cache_gpu17 == True else 0,
831
- 1 if if_save_every_weights18 == True else 0,
832
- version19,
833
- log_interval,
834
- )
835
  )
836
  else:
837
  cmd = (
838
- config.python_cmd
839
- + " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s -li %s"
840
- % (
841
- exp_dir1,
842
- sr2,
843
- 1 if if_f0_3 else 0,
844
- batch_size12,
845
- total_epoch11,
846
- save_epoch10,
847
- ("-pg %s" % pretrained_G14) if pretrained_G14 != "" else "\b",
848
- ("-pd %s" % pretrained_D15) if pretrained_D15 != "" else "\b",
849
- 1 if if_save_latest13 == True else 0,
850
- 1 if if_cache_gpu17 == True else 0,
851
- 1 if if_save_every_weights18 == True else 0,
852
- version19,
853
- log_interval,
854
- )
855
  )
856
  print(cmd)
857
  p = Popen(cmd, shell=True, cwd=now_dir)
858
  global PID
859
  PID = p.pid
860
  p.wait()
861
- return ("训练结束, 您可查看控制台训练日志或实验文件夹下的train.log", {"visible": False, "__type__": "update"}, {"visible": True, "__type__": "update"})
 
862
 
863
 
864
  # but4.click(train_index, [exp_dir1], info3)
@@ -906,7 +918,7 @@ def train_index(exp_dir1, version19):
906
  yield "\n".join(infos)
907
  batch_size_add = 8192
908
  for i in range(0, big_npy.shape[0], batch_size_add):
909
- index.add(big_npy[i : i + batch_size_add])
910
  faiss.write_index(
911
  index,
912
  "%s/added_IVF%s_Flat_nprobe_%s_%s_%s.index"
@@ -923,24 +935,24 @@ def train_index(exp_dir1, version19):
923
 
924
  # but5.click(train1key, [exp_dir1, sr2, if_f0_3, trainset_dir4, spk_id5, gpus6, np7, f0method8, save_epoch10, total_epoch11, batch_size12, if_save_latest13, pretrained_G14, pretrained_D15, gpus16, if_cache_gpu17], info3)
925
  def train1key(
926
- exp_dir1,
927
- sr2,
928
- if_f0_3,
929
- trainset_dir4,
930
- spk_id5,
931
- np7,
932
- f0method8,
933
- save_epoch10,
934
- total_epoch11,
935
- batch_size12,
936
- if_save_latest13,
937
- pretrained_G14,
938
- pretrained_D15,
939
- gpus16,
940
- if_cache_gpu17,
941
- if_save_every_weights18,
942
- version19,
943
- echl
944
  ):
945
  infos = []
946
 
@@ -962,10 +974,10 @@ def train1key(
962
  #########step1:处理数据
963
  open(preprocess_log_path, "w").close()
964
  cmd = (
965
- config.python_cmd
966
- + " trainset_preprocess_pipeline_print.py %s %s %s %s "
967
- % (trainset_dir4, sr_dict[sr2], np7, model_log_dir)
968
- + str(config.noparallel)
969
  )
970
  yield get_info_str(i18n("step1:processing data"))
971
  yield get_info_str(cmd)
@@ -989,9 +1001,9 @@ def train1key(
989
  with open(extract_f0_feature_log_path, "r") as f:
990
  print(f.read())
991
  else:
992
- yield get_info_str(i18n("step2a:No need to extract the pitch"))
993
  #######step2b:提取特征
994
- yield get_info_str(i18n("step2b:Extracting features"))
995
  gpus = gpus16.split("-")
996
  leng = len(gpus)
997
  ps = []
@@ -1014,16 +1026,16 @@ def train1key(
1014
  with open(extract_f0_feature_log_path, "r") as f:
1015
  print(f.read())
1016
  #######step3a:训练模型
1017
- yield get_info_str(i18n("step3a:training model"))
1018
  # 生成filelist
1019
  if if_f0_3:
1020
  f0_dir = "%s/2a_f0" % model_log_dir
1021
  f0nsf_dir = "%s/2b-f0nsf" % model_log_dir
1022
  names = (
1023
- set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)])
1024
- & set([name.split(".")[0] for name in os.listdir(feature_dir)])
1025
- & set([name.split(".")[0] for name in os.listdir(f0_dir)])
1026
- & set([name.split(".")[0] for name in os.listdir(f0nsf_dir)])
1027
  )
1028
  else:
1029
  names = set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)]) & set(
@@ -1076,42 +1088,42 @@ def train1key(
1076
  yield get_info_str("write filelist done")
1077
  if gpus16:
1078
  cmd = (
1079
- config.python_cmd
1080
- +" train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -g %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s"
1081
- % (
1082
- exp_dir1,
1083
- sr2,
1084
- 1 if if_f0_3 else 0,
1085
- batch_size12,
1086
- gpus16,
1087
- total_epoch11,
1088
- save_epoch10,
1089
- ("-pg %s" % pretrained_G14) if pretrained_G14 != "" else "",
1090
- ("-pd %s" % pretrained_D15) if pretrained_D15 != "" else "",
1091
- 1 if if_save_latest13 == True else 0,
1092
- 1 if if_cache_gpu17 == True else 0,
1093
- 1 if if_save_every_weights18 == True else 0,
1094
- version19,
1095
- )
1096
  )
1097
  else:
1098
  cmd = (
1099
- config.python_cmd
1100
- + " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s"
1101
- % (
1102
- exp_dir1,
1103
- sr2,
1104
- 1 if if_f0_3 else 0,
1105
- batch_size12,
1106
- total_epoch11,
1107
- save_epoch10,
1108
- ("-pg %s" % pretrained_G14) if pretrained_G14 != "" else "",
1109
- ("-pd %s" % pretrained_D15) if pretrained_D15 != "" else "",
1110
- 1 if if_save_latest13 == True else 0,
1111
- 1 if if_cache_gpu17 == True else 0,
1112
- 1 if if_save_every_weights18 == True else 0,
1113
- version19,
1114
- )
1115
  )
1116
  yield get_info_str(cmd)
1117
  p = Popen(cmd, shell=True, cwd=now_dir)
@@ -1146,7 +1158,7 @@ def train1key(
1146
  yield get_info_str("adding index")
1147
  batch_size_add = 8192
1148
  for i in range(0, big_npy.shape[0], batch_size_add):
1149
- index.add(big_npy[i : i + batch_size_add])
1150
  faiss.write_index(
1151
  index,
1152
  "%s/added_IVF%s_Flat_nprobe_%s_%s_%s.index"
@@ -1163,16 +1175,17 @@ def whethercrepeornah(radio):
1163
  mango = True if radio == 'mangio-crepe' or radio == 'mangio-crepe-tiny' else False
1164
  return ({"visible": mango, "__type__": "update"})
1165
 
 
1166
  # ckpt_path2.change(change_info_,[ckpt_path2],[sr__,if_f0__])
1167
  def change_info_(ckpt_path):
1168
  if (
1169
- os.path.exists(ckpt_path.replace(os.path.basename(ckpt_path), "train.log"))
1170
- == False
1171
  ):
1172
  return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
1173
  try:
1174
  with open(
1175
- ckpt_path.replace(os.path.basename(ckpt_path), "train.log"), "r"
1176
  ) as f:
1177
  info = eval(f.read().strip("\n").split("\n")[0].split("\t")[-1])
1178
  sr, f0 = info["sample_rate"], info["if_f0"]
@@ -1189,7 +1202,8 @@ from lib.infer_pack.models_onnx import SynthesizerTrnMsNSFsidM
1189
  def export_onnx(ModelPath, ExportedPath, MoeVS=True):
1190
  cpt = torch.load(ModelPath, map_location="cpu")
1191
  cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
1192
- hidden_channels = 256 if cpt.get("version","v1")=="v1"else 768#cpt["config"][-2] # hidden_channels,为768Vec做准备
 
1193
 
1194
  test_phone = torch.rand(1, 200, hidden_channels) # hidden unit
1195
  test_phone_lengths = torch.tensor([200]).long() # hidden unit 长度(貌似没啥用)
@@ -1200,9 +1214,8 @@ def export_onnx(ModelPath, ExportedPath, MoeVS=True):
1200
 
1201
  device = "cpu" # 导出时设备(不影响使用模型)
1202
 
1203
-
1204
  net_g = SynthesizerTrnMsNSFsidM(
1205
- *cpt["config"], is_half=False,version=cpt.get("version","v1")
1206
  ) # fp32导出(C++要支持fp16必须手动将内存重新排列所以暂时不用fp16)
1207
  net_g.load_state_dict(cpt["weight"], strict=False)
1208
  input_names = ["phone", "phone_lengths", "pitch", "pitchf", "ds", "rnd"]
@@ -1235,7 +1248,8 @@ def export_onnx(ModelPath, ExportedPath, MoeVS=True):
1235
  )
1236
  return "Finished"
1237
 
1238
- #region RVC WebUI App
 
1239
 
1240
  def get_presets():
1241
  data = None
@@ -1244,25 +1258,28 @@ def get_presets():
1244
  preset_names = []
1245
  for preset in data['presets']:
1246
  preset_names.append(preset['name'])
1247
-
1248
  return preset_names
1249
 
 
1250
  def change_choices2():
1251
- audio_files=[]
1252
  for filename in os.listdir("./audios"):
1253
- if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
1254
- audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
1255
  return {"choices": sorted(audio_files), "__type__": "update"}, {"__type__": "update"}
1256
-
1257
- audio_files=[]
 
1258
  for filename in os.listdir("./audios"):
1259
- if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
1260
- audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
1261
-
 
1262
  def get_index():
1263
  if check_for_name() != '':
1264
- chosen_model=sorted(names)[0].split(".")[0]
1265
- logs_path="./logs/"+chosen_model
1266
  if os.path.exists(logs_path):
1267
  for file in os.listdir(logs_path):
1268
  if file.endswith(".index"):
@@ -1270,60 +1287,67 @@ def get_index():
1270
  return ''
1271
  else:
1272
  return ''
1273
-
 
1274
  def get_indexes():
1275
- indexes_list=[]
1276
  for dirpath, dirnames, filenames in os.walk("./logs/"):
1277
  for filename in filenames:
1278
  if filename.endswith(".index"):
1279
- indexes_list.append(os.path.join(dirpath,filename))
1280
  if len(indexes_list) > 0:
1281
  return indexes_list
1282
  else:
1283
  return ''
1284
-
 
1285
  def get_name():
1286
  if len(audio_files) > 0:
1287
  return sorted(audio_files)[0]
1288
  else:
1289
  return ''
1290
-
 
1291
  def save_to_wav(record_button):
1292
  if record_button is None:
1293
  pass
1294
  else:
1295
- path_to_file=record_button
1296
- new_name = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")+'.wav'
1297
- new_path='./audios/'+new_name
1298
- shutil.move(path_to_file,new_path)
1299
  return new_path
1300
-
 
1301
  def save_to_wav2(dropbox):
1302
- file_path=dropbox.name
1303
- shutil.move(file_path,'./audios')
1304
- return os.path.join('./audios',os.path.basename(file_path))
1305
-
 
1306
  def match_index(sid0):
1307
- folder=sid0.split(".")[0]
1308
- parent_dir="./logs/"+folder
1309
  if os.path.exists(parent_dir):
1310
  for filename in os.listdir(parent_dir):
1311
  if filename.endswith(".index"):
1312
- index_path=os.path.join(parent_dir,filename)
1313
  return index_path
1314
  else:
1315
  return ''
1316
-
 
1317
  def check_for_name():
1318
  if len(names) > 0:
1319
  return sorted(names)[0]
1320
  else:
1321
  return ''
1322
-
 
1323
  def download_from_url(url, model):
1324
  if url == '':
1325
  return "URL cannot be left empty."
1326
- if model =='':
1327
  return "You need to name your model. For example: My-Model"
1328
  url = url.strip()
1329
  zip_dirs = ["zips", "unzips"]
@@ -1344,7 +1368,7 @@ def download_from_url(url, model):
1344
  subprocess.run(["wget", url, "-O", zipfile_path])
1345
  for filename in os.listdir("./zips"):
1346
  if filename.endswith(".zip"):
1347
- zipfile_path = os.path.join("./zips/",filename)
1348
  shutil.unpack_archive(zipfile_path, "./unzips", 'zip')
1349
  else:
1350
  return "No zipfile found."
@@ -1353,16 +1377,20 @@ def download_from_url(url, model):
1353
  file_path = os.path.join(root, file)
1354
  if file.endswith(".index"):
1355
  os.mkdir(f'./logs/{model}')
1356
- shutil.copy2(file_path,f'./logs/{model}')
1357
  elif "G_" not in file and "D_" not in file and file.endswith(".pth"):
1358
- shutil.copy(file_path,f'./weights/{model}.pth')
1359
  shutil.rmtree("zips")
1360
  shutil.rmtree("unzips")
1361
  return "Success."
1362
  except:
1363
  return "There's been an error."
 
 
1364
  def success_message(face):
1365
  return f'{face.name} has been uploaded.', 'None'
 
 
1366
  def mouth(size, face, voice, faces):
1367
  if size == 'Half':
1368
  size = 2
@@ -1376,21 +1404,26 @@ def mouth(size, face, voice, faces):
1376
  elif faces == 'Andrew Tate':
1377
  character = '/content/wav2lip-HD/inputs/tate-7.mp4'
1378
  command = "python inference.py " \
1379
- "--checkpoint_path checkpoints/wav2lip.pth " \
1380
- f"--face {character} " \
1381
- f"--audio {voice} " \
1382
- "--pads 0 20 0 0 " \
1383
- "--outfile /content/wav2lip-HD/outputs/result.mp4 " \
1384
- "--fps 24 " \
1385
- f"--resize_factor {size}"
1386
  process = subprocess.Popen(command, shell=True, cwd='/content/wav2lip-HD/Wav2Lip-master')
1387
  stdout, stderr = process.communicate()
1388
  return '/content/wav2lip-HD/outputs/result.mp4', 'Animation completed.'
1389
- eleven_voices = ['Adam','Antoni','Josh','Arnold','Sam','Bella','Rachel','Domi','Elli']
1390
- eleven_voices_ids=['pNInz6obpgDQGcFmaJgB','ErXwobaYiN019PkySvjV','TxGEqnHWrfWFTfGW9XjX','VR6AewLTigWG4xSOukaG','yoZ06aMxZJJ28mfd3POQ','EXAVITQu4vr4xnSDxMaL','21m00Tcm4TlvDq8ikWAM','AZnzlk1XvdvUeBnXmlld','MF3mGyEYCl7XYWbV9V6O']
 
 
 
 
1391
  chosen_voice = dict(zip(eleven_voices, eleven_voices_ids))
1392
 
1393
- def stoptraining(mim):
 
1394
  if int(mim) == 1:
1395
  try:
1396
  CSVutil('csvdb/stop.csv', 'w+', 'stop', 'True')
@@ -1398,45 +1431,45 @@ def stoptraining(mim):
1398
  except Exception as e:
1399
  print(f"Couldn't click due to {e}")
1400
  return (
1401
- {"visible": False, "__type__": "update"},
1402
  {"visible": True, "__type__": "update"},
1403
  )
1404
 
1405
 
1406
  def elevenTTS(xiapi, text, id, lang):
1407
- if xiapi!= '' and id !='':
1408
  choice = chosen_voice[id]
1409
  CHUNK_SIZE = 1024
1410
  url = f"https://api.elevenlabs.io/v1/text-to-speech/{choice}"
1411
  headers = {
1412
- "Accept": "audio/mpeg",
1413
- "Content-Type": "application/json",
1414
- "xi-api-key": xiapi
1415
  }
1416
  if lang == 'en':
1417
  data = {
1418
- "text": text,
1419
- "model_id": "eleven_monolingual_v1",
1420
- "voice_settings": {
1421
- "stability": 0.5,
1422
- "similarity_boost": 0.5
1423
- }
1424
  }
1425
  else:
1426
  data = {
1427
- "text": text,
1428
- "model_id": "eleven_multilingual_v1",
1429
- "voice_settings": {
1430
- "stability": 0.5,
1431
- "similarity_boost": 0.5
1432
- }
1433
  }
1434
 
1435
  response = requests.post(url, json=data, headers=headers)
1436
  with open('./temp_eleven.mp3', 'wb') as f:
1437
- for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
1438
- if chunk:
1439
- f.write(chunk)
1440
  aud_path = save_to_wav('./temp_eleven.mp3')
1441
  return aud_path, aud_path
1442
  else:
@@ -1445,6 +1478,7 @@ def elevenTTS(xiapi, text, id, lang):
1445
  aud_path = save_to_wav('./temp_gTTS.mp3')
1446
  return aud_path, aud_path
1447
 
 
1448
  def upload_to_dataset(files, dir):
1449
  if dir == '':
1450
  dir = './dataset'
@@ -1452,11 +1486,12 @@ def upload_to_dataset(files, dir):
1452
  os.makedirs(dir)
1453
  count = 0
1454
  for file in files:
1455
- path=file.name
1456
- shutil.copy2(path,dir)
1457
  count += 1
1458
- return f' {count} files uploaded to {dir}.'
1459
-
 
1460
  def zip_downloader(model):
1461
  if not os.path.exists(f'./weights/{model}.pth'):
1462
  return {"__type__": "update"}, f'Make sure the Voice Name is correct. I could not find {model}.pth'
@@ -1470,11 +1505,12 @@ def zip_downloader(model):
1470
  else:
1471
  return f'./weights/{model}.pth', "Could not find Index file."
1472
 
 
1473
  with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1474
- # gr.LogoutButton()
1475
  with gr.Tabs():
1476
  with gr.TabItem("Interfeys"):
1477
- gr.HTML ("<center><h1> Voice DeepFake </h1></span>")
1478
  # gr.HTML("<center><h3> Если вы хотите использовать это пространство в частном порядке, я рекомендую продублировать его. </h3></span>")
1479
  # with gr.Row():
1480
  # gr.Markdown(
@@ -1497,8 +1533,10 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1497
  refresh_button = gr.Button("Yangilash", variant="primary")
1498
  if check_for_name() != '':
1499
  get_vc(sorted(names)[0])
1500
- vc_transform0 = gr.Number(label="Kengaytirilgan: Bu yerda siz ovoz balandligini o'zgartirishingiz yoki uni 0 da qoldirishingiz mumkin.", value=0)
1501
- #clean_button = gr.Button(i18n("卸载音色省显存"), variant="primary")
 
 
1502
  spk_item = gr.Slider(
1503
  minimum=0,
1504
  maximum=2333,
@@ -1508,7 +1546,7 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1508
  visible=False,
1509
  interactive=True,
1510
  )
1511
- #clean_button.click(fn=clean, inputs=[], outputs=[sid0])
1512
  sid0.change(
1513
  fn=get_vc,
1514
  inputs=[sid0],
@@ -1518,15 +1556,17 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1518
  with gr.Row():
1519
  with gr.Column():
1520
  with gr.Row():
1521
- dropbox = gr.File(label='Ovoz yozishingizni shu yerga yuboring va "Qayta yuklash" tugmasini bosing.')
 
1522
  with gr.Row():
1523
- record_button=gr.Audio(source="microphone", label="Ovozni mikrofondan yozib oling.", type="filepath")
 
1524
  with gr.Row():
1525
  input_audio0 = gr.Dropdown(
1526
  label="2.Audio yozuvni tanlang.",
1527
  value="./audios/someguy.mp3",
1528
  choices=audio_files
1529
- )
1530
  dropbox.upload(fn=save_to_wav2, inputs=[dropbox], outputs=[input_audio0])
1531
  dropbox.upload(fn=change_choices2, inputs=[], outputs=[input_audio0])
1532
  refresh_button2 = gr.Button("Yangilash", variant="primary", size='sm')
@@ -1544,12 +1584,13 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1544
  with gr.Row():
1545
  with gr.Accordion('Wav2Lip', open=False, visible=False):
1546
  with gr.Row():
1547
- size = gr.Radio(label='Resolution:',choices=['Half','Full'])
1548
- face = gr.UploadButton("Upload A Character",type='file')
1549
- faces = gr.Dropdown(label="OR Choose one:", choices=['None','Ben Shapiro','Andrew Tate'])
 
1550
  with gr.Row():
1551
- preview = gr.Textbox(label="Status:",interactive=False)
1552
- face.upload(fn=success_message,inputs=[face], outputs=[preview, faces])
1553
  with gr.Row():
1554
  animation = gr.Video(type='filepath')
1555
  refresh_button2.click(fn=change_choices2, inputs=[], outputs=[input_audio0, animation])
@@ -1563,11 +1604,11 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1563
  choices=get_indexes(),
1564
  value=get_index(),
1565
  interactive=True,
1566
- )
1567
- sid0.change(fn=match_index, inputs=[sid0],outputs=[file_index1])
1568
  refresh_button.click(
1569
  fn=change_choices, inputs=[], outputs=[sid0, file_index1]
1570
- )
1571
  # file_big_npy1 = gr.Textbox(
1572
  # label=i18n("特征文件路径"),
1573
  # value="E:\\codes\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
@@ -1579,7 +1620,7 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1579
  label=i18n("Qidiruv funksiyasining nisbati (men uni 0 ga o'rnatishni tavsiya qilaman):"),
1580
  value=0.66,
1581
  interactive=True,
1582
- )
1583
  vc_output2 = gr.Audio(
1584
  label="Audio ma'lumotlarni chiqarish (yuklab olish uchun o'ng burchakdagi uchta nuqta ustiga bosing)",
1585
  type='filepath',
@@ -1589,11 +1630,12 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1589
  with gr.Accordion("Qo'shimcha sozlamalar", open=False):
1590
  f0method0 = gr.Radio(
1591
  label='Majburiy emas: Ovozni ajratib olish algoritmini o\'zgartiring.',
1592
- choices=["pm", "dio", "crepe-tiny", "mangio-crepe-tiny", "crepe", "harvest", "mangio-crepe", "rmvpe"], # Fork Feature. Add Crepe-Tiny
 
1593
  value="rmvpe",
1594
  interactive=True,
1595
  )
1596
-
1597
  crepe_hop_length = gr.Slider(
1598
  minimum=1,
1599
  maximum=512,
@@ -1602,16 +1644,17 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1602
  value=120,
1603
  interactive=True,
1604
  visible=False,
1605
- )
1606
  f0method0.change(fn=whethercrepeornah, inputs=[f0method0], outputs=[crepe_hop_length])
1607
  filter_radius0 = gr.Slider(
1608
  minimum=0,
1609
  maximum=7,
1610
- label=i18n("Agar >=3 boʻlsa: toʻplangan ovoz balandligi natijalariga median filtrlashni qoʻllang. Qiymat filtrlash radiusini ifodalaydi va nafas olishni qisqartirishi mumkin"),
 
1611
  value=3,
1612
  step=1,
1613
  interactive=True,
1614
- )
1615
  resample_sr0 = gr.Slider(
1616
  minimum=0,
1617
  maximum=48000,
@@ -1620,22 +1663,24 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1620
  step=1,
1621
  interactive=True,
1622
  visible=False
1623
- )
1624
  rms_mix_rate0 = gr.Slider(
1625
  minimum=0,
1626
  maximum=1,
1627
- label=i18n("Chiqish ovozi konvertini almashtirish yoki aralashtirish uchun kirish ovozi konvertidan foydalaning. Bu nisbat 1 ga qanchalik yaqin bo'lsa, chiqish signali konvertidan shunchalik ko'p foydalaniladi:"),
 
1628
  value=0.21,
1629
  interactive=True,
1630
- )
1631
  protect0 = gr.Slider(
1632
  minimum=0,
1633
  maximum=0.5,
1634
- label=i18n("Elektron musiqadagi tanaffuslar kabi artefaktlarning oldini olish uchun ovozsiz undosh tovushlarni va nafas tovushlarini himoya qiladi. O'chirish uchun qiymatni 0,5 ga o'rnating. Xavfsizlikni oshirish uchun qiymatni kamaytiring, lekin bu indekslash aniqligini kamaytirishi mumkin:"),
 
1635
  value=0.33,
1636
  step=0.01,
1637
  interactive=True,
1638
- )
1639
  formanting = gr.Checkbox(
1640
  value=bool(DoFormant),
1641
  label="[EXPERIMENTAL] Formant shift inference audio",
@@ -1643,7 +1688,7 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1643
  interactive=True,
1644
  visible=False,
1645
  )
1646
-
1647
  formant_preset = gr.Dropdown(
1648
  value='',
1649
  choices=get_fshift_presets(),
@@ -1655,19 +1700,19 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1655
  visible=bool(DoFormant),
1656
  variant='primary',
1657
  )
1658
- #formant_refresh_button = ToolButton( elem_id='1')
1659
- #create_refresh_button(formant_preset, lambda: {"choices": formant_preset}, "refresh_list_shiftpresets")
1660
-
1661
  qfrency = gr.Slider(
1662
- value=Quefrency,
1663
- info="Default value is 1.0",
1664
- label="Quefrency for formant shifting",
1665
- minimum=0.0,
1666
- maximum=16.0,
1667
- step=0.1,
1668
- visible=bool(DoFormant),
1669
- interactive=True,
1670
- )
1671
  tmbre = gr.Slider(
1672
  value=Timbre,
1673
  info="Default value is 1.0",
@@ -1678,16 +1723,22 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1678
  visible=bool(DoFormant),
1679
  interactive=True,
1680
  )
1681
-
1682
- formant_preset.change(fn=preset_apply, inputs=[formant_preset, qfrency, tmbre], outputs=[qfrency, tmbre])
 
1683
  frmntbut = gr.Button("Apply", variant="primary", visible=bool(DoFormant))
1684
- formanting.change(fn=formant_enabled,inputs=[formanting,qfrency,tmbre,frmntbut,formant_preset,formant_refresh_button],outputs=[formanting,qfrency,tmbre,frmntbut,formant_preset,formant_refresh_button])
1685
- frmntbut.click(fn=formant_apply,inputs=[qfrency, tmbre], outputs=[qfrency, tmbre])
1686
- formant_refresh_button.click(fn=update_fshift_presets,inputs=[formant_preset, qfrency, tmbre],outputs=[formant_preset, qfrency, tmbre])
 
 
 
 
 
1687
  with gr.Row():
1688
  vc_output1 = gr.Textbox("")
1689
  f0_file = gr.File(label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调"), visible=False)
1690
-
1691
  but0.click(
1692
  vc_single,
1693
  [
@@ -1708,8 +1759,8 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1708
  ],
1709
  [vc_output1, vc_output2],
1710
  )
1711
-
1712
- with gr.Accordion("Batch Conversion",open=False, visible=False):
1713
  with gr.Row():
1714
  with gr.Column():
1715
  vc_transform1 = gr.Number(
@@ -1834,14 +1885,16 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1834
  # """
1835
  # )
1836
  with gr.Row():
1837
- url=gr.Textbox(label="Model URL manzilini kiriting:", placeholder=".pth va .index fayllarni o'z ichiga olgan zipga havolani kiriting")
 
1838
  with gr.Row():
1839
  model = gr.Textbox(label="Model nomi:")
1840
- download_button=gr.Button("Yuklash")
1841
  with gr.Row():
1842
- status_bar=gr.Textbox(label="")
1843
  download_button.click(fn=download_from_url, inputs=[url, model], outputs=[status_bar])
1844
 
 
1845
  def has_two_files_in_pretrained_folder():
1846
  pretrained_folder = "./pretrained/"
1847
  if not os.path.exists(pretrained_folder):
@@ -1851,8 +1904,9 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1851
  num_files = len(files_in_folder)
1852
  return num_files >= 2
1853
 
1854
- if has_two_files_in_pretrained_folder():
1855
- print("Pretrained weights are downloaded. Training tab enabled!\n-------------------------------")
 
1856
  with gr.TabItem("Train", visible=False):
1857
  with gr.Row():
1858
  with gr.Column():
@@ -1888,10 +1942,13 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1888
  visible=True
1889
  )
1890
  trainset_dir4 = gr.Textbox(label="Path to your dataset (audios, not zip):", value="./dataset")
1891
- easy_uploader = gr.Files(label='OR Drop your audios here. They will be uploaded in your dataset path above.',file_types=['audio'])
 
 
1892
  but1 = gr.Button("1. Process The Dataset", variant="primary")
1893
  info1 = gr.Textbox(label="Status (wait until it says 'end preprocess'):", value="")
1894
- easy_uploader.upload(fn=upload_to_dataset, inputs=[easy_uploader, trainset_dir4], outputs=[info1])
 
1895
  but1.click(
1896
  preprocess_dataset, [trainset_dir4, exp_dir1, sr2, np7], [info1]
1897
  )
@@ -1917,11 +1974,12 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1917
  label=i18n(
1918
  "选择音高提取算法:输入歌声可用pm提速,高质量语音但CPU差可用dio提速,harvest质量更好但慢"
1919
  ),
1920
- choices=["harvest","crepe", "mangio-crepe", "rmvpe"], # Fork feature: Crepe on f0 extraction for training.
 
1921
  value="rmvpe",
1922
  interactive=True,
1923
  )
1924
-
1925
  extraction_crepe_hop_length = gr.Slider(
1926
  minimum=1,
1927
  maximum=512,
@@ -1931,15 +1989,17 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1931
  interactive=True,
1932
  visible=False,
1933
  )
1934
- f0method8.change(fn=whethercrepeornah, inputs=[f0method8], outputs=[extraction_crepe_hop_length])
 
1935
  but2 = gr.Button("2. Pitch Extraction", variant="primary")
1936
- info2 = gr.Textbox(label="Status(Check the Colab Notebook's cell output):", value="", max_lines=8)
 
1937
  but2.click(
1938
- extract_f0_feature,
1939
- [gpus6, np7, f0method8, if_f0_3, exp_dir1, version19, extraction_crepe_hop_length],
1940
- [info2],
1941
- )
1942
- with gr.Row():
1943
  with gr.Column():
1944
  total_epoch11 = gr.Slider(
1945
  minimum=1,
@@ -1955,15 +2015,17 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1955
  visible=False,
1956
  )
1957
  but3 = gr.Button("3. Train Model", variant="primary", visible=True)
1958
-
1959
- but3.click(fn=stoptraining, inputs=[gr.Number(value=0, visible=False)], outputs=[but3, butstop])
1960
- butstop.click(fn=stoptraining, inputs=[gr.Number(value=1, visible=False)], outputs=[butstop, but3])
1961
-
1962
-
 
1963
  but4 = gr.Button("4.Train Index", variant="primary")
1964
- info3 = gr.Textbox(label="Status(Check the Colab Notebook's cell output):", value="", max_lines=10)
 
1965
  with gr.Accordion("Training Preferences (You can leave these as they are)", open=False):
1966
- #gr.Markdown(value=i18n("step3: 填写训练设置, 开始训练模型和索引"))
1967
  with gr.Column():
1968
  save_epoch10 = gr.Slider(
1969
  minimum=1,
@@ -2082,13 +2144,5 @@ with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
2082
  info3,
2083
  )
2084
 
2085
- # else:
2086
-
2087
- # print(
2088
- # "Pretrained weights not downloaded. Disabling training tab.\n"
2089
- # "Wondering how to train a voice? Visit here for the RVC model training guide: https://t.ly/RVC_Training_Guide\n"
2090
- # "-------------------------------\n"
2091
- # )
2092
-
2093
  app.queue(concurrency_count=511, max_size=1022).launch(auth=("admin", "admin"), share=False, quiet=True)
2094
- #endregion
 
1
  import subprocess, torch, os, traceback, sys, warnings, shutil, numpy as np
2
  from mega import Mega
3
+
4
  os.environ["no_proxy"] = "localhost, 127.0.0.1, ::1"
5
  import threading
6
  from time import sleep
 
9
  from random import shuffle
10
  import json, datetime, requests
11
  from gtts import gTTS
12
+
13
  now_dir = os.getcwd()
14
  sys.path.append(now_dir)
15
  tmp = os.path.join(now_dir, "TEMP")
 
40
  try:
41
  DoFormant, Quefrency, Timbre = CSVutil('csvdb/formanting.csv', 'r', 'formanting')
42
  DoFormant = (
43
+ lambda DoFormant: True if DoFormant.lower() == 'true' else (
44
+ False if DoFormant.lower() == 'false' else DoFormant)
45
  )(DoFormant)
46
  except (ValueError, TypeError, IndexError):
47
  DoFormant, Quefrency, Timbre = False, 1.0, 1.0
48
  CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, Quefrency, Timbre)
49
 
50
+
51
  def download_models():
52
  # Download hubert base model if not present
53
  if not os.path.isfile('./hubert_base.pt'):
 
58
  f.write(response.content)
59
  print("Downloaded hubert base model file successfully. File saved to ./hubert_base.pt.")
60
  else:
61
+ raise Exception(
62
+ "Failed to download hubert base model file. Status code: " + str(response.status_code) + ".")
63
+
64
  # Download rmvpe model if not present
65
  if not os.path.isfile('./rmvpe.pt'):
66
+ response = requests.get(
67
+ 'https://drive.usercontent.google.com/download?id=1Hkn4kNuVFRCNQwyxQFRtmzmMBGpQxptI&export=download&authuser=0&confirm=t&uuid=0b3a40de-465b-4c65-8c41-135b0b45c3f7&at=APZUnTV3lA3LnyTbeuduura6Dmi2:1693724254058')
68
 
69
  if response.status_code == 200:
70
  with open('./rmvpe.pt', 'wb') as f:
 
73
  else:
74
  raise Exception("Failed to download rmvpe model file. Status code: " + str(response.status_code) + ".")
75
 
76
+
77
  download_models()
78
 
79
  print("\n-------------------------------\nRVC v2 Easy GUI (Local Edition)\n-------------------------------\n")
80
 
81
+
82
  def formant_apply(qfrency, tmbre):
83
  Quefrency = qfrency
84
  Timbre = tmbre
85
  DoFormant = True
86
  CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, qfrency, tmbre)
87
+
88
  return ({"value": Quefrency, "__type__": "update"}, {"value": Timbre, "__type__": "update"})
89
 
90
+
91
  def get_fshift_presets():
92
  fshift_presets_list = []
93
  for dirpath, _, filenames in os.walk("./formantshiftcfg/"):
94
  for filename in filenames:
95
  if filename.endswith(".txt"):
96
+ fshift_presets_list.append(os.path.join(dirpath, filename).replace('\\', '/'))
97
+
98
  if len(fshift_presets_list) > 0:
99
  return fshift_presets_list
100
  else:
101
  return ''
102
 
103
 
 
104
  def formant_enabled(cbox, qfrency, tmbre, frmntapply, formantpreset, formant_refresh_button):
 
105
  if (cbox):
106
 
107
  DoFormant = True
108
  CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, qfrency, tmbre)
109
+ # print(f"is checked? - {cbox}\ngot {DoFormant}")
110
+
111
  return (
112
  {"value": True, "__type__": "update"},
113
  {"visible": True, "__type__": "update"},
 
116
  {"visible": True, "__type__": "update"},
117
  {"visible": True, "__type__": "update"},
118
  )
119
+
120
+
121
  else:
122
+
123
  DoFormant = False
124
  CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, qfrency, tmbre)
125
+
126
+ # print(f"is checked? - {cbox}\ngot {DoFormant}")
127
  return (
128
  {"value": False, "__type__": "update"},
129
  {"visible": False, "__type__": "update"},
 
133
  {"visible": False, "__type__": "update"},
134
  {"visible": False, "__type__": "update"},
135
  )
 
136
 
137
 
138
  def preset_apply(preset, qfer, tmbr):
 
140
  with open(str(preset), 'r') as p:
141
  content = p.readlines()
142
  qfer, tmbr = content[0].split('\n')[0], content[1]
143
+
144
  formant_apply(qfer, tmbr)
145
  else:
146
  pass
147
  return ({"value": qfer, "__type__": "update"}, {"value": tmbr, "__type__": "update"})
148
 
149
+
150
  def update_fshift_presets(preset, qfrency, tmbre):
 
151
  qfrency, tmbre = preset_apply(preset, qfrency, tmbre)
152
+
153
  if (str(preset) != ''):
154
  with open(str(preset), 'r') as p:
155
  content = p.readlines()
156
  qfrency, tmbre = content[0].split('\n')[0], content[1]
157
+
158
  formant_apply(qfrency, tmbre)
159
  else:
160
  pass
 
164
  {"value": tmbre, "__type__": "update"},
165
  )
166
 
167
+
168
  i18n = I18nAuto()
169
+ # i18n.print()
170
  # 判断是否有能用来训练和加速推理的N卡
171
  ngpu = torch.cuda.device_count()
172
  gpu_infos = []
 
178
  for i in range(ngpu):
179
  gpu_name = torch.cuda.get_device_name(i)
180
  if (
181
+ "10" in gpu_name
182
+ or "16" in gpu_name
183
+ or "20" in gpu_name
184
+ or "30" in gpu_name
185
+ or "40" in gpu_name
186
+ or "A2" in gpu_name.upper()
187
+ or "A3" in gpu_name.upper()
188
+ or "A4" in gpu_name.upper()
189
+ or "P4" in gpu_name.upper()
190
+ or "A50" in gpu_name.upper()
191
+ or "A60" in gpu_name.upper()
192
+ or "70" in gpu_name
193
+ or "80" in gpu_name
194
+ or "90" in gpu_name
195
+ or "M4" in gpu_name.upper()
196
+ or "T4" in gpu_name.upper()
197
+ or "TITAN" in gpu_name.upper()
198
  ): # A10#A100#V100#A40#P40#M40#K80#A4500
199
  if_gpu_ok = True # 至少有一张能用的N卡
200
  gpu_infos.append("%s\t%s" % (i, gpu_name))
 
233
 
234
  hubert_model = None
235
 
236
+
237
  def load_hubert():
238
  global hubert_model
239
  models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
 
262
  index_paths.append("%s/%s" % (root, name))
263
 
264
 
 
265
  def vc_single(
266
+ sid,
267
+ input_audio_path,
268
+ f0_up_key,
269
+ f0_file,
270
+ f0_method,
271
+ file_index,
272
+ # file_index2,
273
+ # file_big_npy,
274
+ index_rate,
275
+ filter_radius,
276
+ resample_sr,
277
+ rms_mix_rate,
278
+ protect,
279
+ crepe_hop_length,
280
  ): # spk_item, input_audio0, vc_transform0,f0_file,f0method0
281
  global tgt_sr, net_g, vc, hubert_model, version
282
  if input_audio_path is None:
 
346
 
347
 
348
  def vc_multi(
349
+ sid,
350
+ dir_path,
351
+ opt_root,
352
+ paths,
353
+ f0_up_key,
354
+ f0_method,
355
+ file_index,
356
+ file_index2,
357
+ # file_big_npy,
358
+ index_rate,
359
+ filter_radius,
360
+ resample_sr,
361
+ rms_mix_rate,
362
+ protect,
363
+ format1,
364
+ crepe_hop_length,
365
  ):
366
  try:
367
  dir_path = (
 
423
  except:
424
  yield traceback.format_exc()
425
 
426
+
427
  # 一个选项卡全局只能有一个音色
428
  def get_vc(sid):
429
  global n_spk, tgt_sr, net_g, vc, cpt, version
 
543
  f = open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "w")
544
  f.close()
545
  cmd = (
546
+ config.python_cmd
547
+ + " trainset_preprocess_pipeline_print.py %s %s %s %s/logs/%s "
548
+ % (trainset_dir, sr, n_p, now_dir, exp_dir)
549
+ + str(config.noparallel)
550
  )
551
  print(cmd)
552
  p = Popen(cmd, shell=True) # , stdin=PIPE, stdout=PIPE,stderr=PIPE,cwd=now_dir
 
570
  print(log)
571
  yield log
572
 
573
+
574
  # but2.click(extract_f0,[gpus6,np7,f0method8,if_f0_3,trainset_dir4],[info2])
575
  def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, echl):
576
  gpus = gpus.split("-")
 
598
  ).start()
599
  while 1:
600
  with open(
601
+ "%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r"
602
  ) as f:
603
  yield (f.read())
604
  sleep(1)
 
620
  ps = []
621
  for idx, n_g in enumerate(gpus):
622
  cmd = (
623
+ config.python_cmd
624
+ + " extract_feature_print.py %s %s %s %s %s/logs/%s %s"
625
+ % (
626
+ config.device,
627
+ leng,
628
+ idx,
629
+ n_g,
630
+ now_dir,
631
+ exp_dir,
632
+ version19,
633
+ )
634
  )
635
  print(cmd)
636
  p = Popen(
 
673
  {"visible": True, "__type__": "update"}
674
  )
675
 
676
+
677
  def change_version19(sr2, if_f0_3, version19):
678
  path_str = "" if version19 == "v1" else "_v2"
679
  f0_str = "f0" if if_f0_3 else ""
 
727
  log_interval += 1
728
  return log_interval
729
 
730
+
731
  # but3.click(click_train,[exp_dir1,sr2,if_f0_3,save_epoch10,total_epoch11,batch_size12,if_save_latest13,pretrained_G14,pretrained_D15,gpus16])
732
  def click_train(
733
+ exp_dir1,
734
+ sr2,
735
+ if_f0_3,
736
+ spk_id5,
737
+ save_epoch10,
738
+ total_epoch11,
739
+ batch_size12,
740
+ if_save_latest13,
741
+ pretrained_G14,
742
+ pretrained_D15,
743
+ gpus16,
744
+ if_cache_gpu17,
745
+ if_save_every_weights18,
746
+ version19,
747
  ):
748
  CSVutil('csvdb/stop.csv', 'w+', 'formanting', False)
749
  # 生成filelist
 
755
  if version19 == "v1"
756
  else "%s/3_feature768" % (exp_dir)
757
  )
758
+
759
  log_interval = set_log_interval(exp_dir, batch_size12)
760
+
761
  if if_f0_3:
762
  f0_dir = "%s/2a_f0" % (exp_dir)
763
  f0nsf_dir = "%s/2b-f0nsf" % (exp_dir)
764
  names = (
765
+ set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)])
766
+ & set([name.split(".")[0] for name in os.listdir(feature_dir)])
767
+ & set([name.split(".")[0] for name in os.listdir(f0_dir)])
768
+ & set([name.split(".")[0] for name in os.listdir(f0nsf_dir)])
769
  )
770
  else:
771
  names = set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)]) & set(
 
825
  print("no pretrained Discriminator")
826
  if gpus16:
827
  cmd = (
828
+ config.python_cmd
829
+ + " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -g %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s -li %s"
830
+ % (
831
+ exp_dir1,
832
+ sr2,
833
+ 1 if if_f0_3 else 0,
834
+ batch_size12,
835
+ gpus16,
836
+ total_epoch11,
837
+ save_epoch10,
838
+ ("-pg %s" % pretrained_G14) if pretrained_G14 != "" else "",
839
+ ("-pd %s" % pretrained_D15) if pretrained_D15 != "" else "",
840
+ 1 if if_save_latest13 == True else 0,
841
+ 1 if if_cache_gpu17 == True else 0,
842
+ 1 if if_save_every_weights18 == True else 0,
843
+ version19,
844
+ log_interval,
845
+ )
846
  )
847
  else:
848
  cmd = (
849
+ config.python_cmd
850
+ + " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s -li %s"
851
+ % (
852
+ exp_dir1,
853
+ sr2,
854
+ 1 if if_f0_3 else 0,
855
+ batch_size12,
856
+ total_epoch11,
857
+ save_epoch10,
858
+ ("-pg %s" % pretrained_G14) if pretrained_G14 != "" else "\b",
859
+ ("-pd %s" % pretrained_D15) if pretrained_D15 != "" else "\b",
860
+ 1 if if_save_latest13 == True else 0,
861
+ 1 if if_cache_gpu17 == True else 0,
862
+ 1 if if_save_every_weights18 == True else 0,
863
+ version19,
864
+ log_interval,
865
+ )
866
  )
867
  print(cmd)
868
  p = Popen(cmd, shell=True, cwd=now_dir)
869
  global PID
870
  PID = p.pid
871
  p.wait()
872
+ return ("训练结束, 您可查看控制台训练日志或实验文件夹下的train.log", {"visible": False, "__type__": "update"},
873
+ {"visible": True, "__type__": "update"})
874
 
875
 
876
  # but4.click(train_index, [exp_dir1], info3)
 
918
  yield "\n".join(infos)
919
  batch_size_add = 8192
920
  for i in range(0, big_npy.shape[0], batch_size_add):
921
+ index.add(big_npy[i: i + batch_size_add])
922
  faiss.write_index(
923
  index,
924
  "%s/added_IVF%s_Flat_nprobe_%s_%s_%s.index"
 
935
 
936
  # but5.click(train1key, [exp_dir1, sr2, if_f0_3, trainset_dir4, spk_id5, gpus6, np7, f0method8, save_epoch10, total_epoch11, batch_size12, if_save_latest13, pretrained_G14, pretrained_D15, gpus16, if_cache_gpu17], info3)
937
  def train1key(
938
+ exp_dir1,
939
+ sr2,
940
+ if_f0_3,
941
+ trainset_dir4,
942
+ spk_id5,
943
+ np7,
944
+ f0method8,
945
+ save_epoch10,
946
+ total_epoch11,
947
+ batch_size12,
948
+ if_save_latest13,
949
+ pretrained_G14,
950
+ pretrained_D15,
951
+ gpus16,
952
+ if_cache_gpu17,
953
+ if_save_every_weights18,
954
+ version19,
955
+ echl
956
  ):
957
  infos = []
958
 
 
974
  #########step1:处理数据
975
  open(preprocess_log_path, "w").close()
976
  cmd = (
977
+ config.python_cmd
978
+ + " trainset_preprocess_pipeline_print.py %s %s %s %s "
979
+ % (trainset_dir4, sr_dict[sr2], np7, model_log_dir)
980
+ + str(config.noparallel)
981
  )
982
  yield get_info_str(i18n("step1:processing data"))
983
  yield get_info_str(cmd)
 
1001
  with open(extract_f0_feature_log_path, "r") as f:
1002
  print(f.read())
1003
  else:
1004
+ yield get_info_str(i18n("step2a:无需提取音高"))
1005
  #######step2b:提取特征
1006
+ yield get_info_str(i18n("step2b:正在提取特征"))
1007
  gpus = gpus16.split("-")
1008
  leng = len(gpus)
1009
  ps = []
 
1026
  with open(extract_f0_feature_log_path, "r") as f:
1027
  print(f.read())
1028
  #######step3a:训练模型
1029
+ yield get_info_str(i18n("step3a:正在训练模型"))
1030
  # 生成filelist
1031
  if if_f0_3:
1032
  f0_dir = "%s/2a_f0" % model_log_dir
1033
  f0nsf_dir = "%s/2b-f0nsf" % model_log_dir
1034
  names = (
1035
+ set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)])
1036
+ & set([name.split(".")[0] for name in os.listdir(feature_dir)])
1037
+ & set([name.split(".")[0] for name in os.listdir(f0_dir)])
1038
+ & set([name.split(".")[0] for name in os.listdir(f0nsf_dir)])
1039
  )
1040
  else:
1041
  names = set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)]) & set(
 
1088
  yield get_info_str("write filelist done")
1089
  if gpus16:
1090
  cmd = (
1091
+ config.python_cmd
1092
+ + " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -g %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s"
1093
+ % (
1094
+ exp_dir1,
1095
+ sr2,
1096
+ 1 if if_f0_3 else 0,
1097
+ batch_size12,
1098
+ gpus16,
1099
+ total_epoch11,
1100
+ save_epoch10,
1101
+ ("-pg %s" % pretrained_G14) if pretrained_G14 != "" else "",
1102
+ ("-pd %s" % pretrained_D15) if pretrained_D15 != "" else "",
1103
+ 1 if if_save_latest13 == True else 0,
1104
+ 1 if if_cache_gpu17 == True else 0,
1105
+ 1 if if_save_every_weights18 == True else 0,
1106
+ version19,
1107
+ )
1108
  )
1109
  else:
1110
  cmd = (
1111
+ config.python_cmd
1112
+ + " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s"
1113
+ % (
1114
+ exp_dir1,
1115
+ sr2,
1116
+ 1 if if_f0_3 else 0,
1117
+ batch_size12,
1118
+ total_epoch11,
1119
+ save_epoch10,
1120
+ ("-pg %s" % pretrained_G14) if pretrained_G14 != "" else "",
1121
+ ("-pd %s" % pretrained_D15) if pretrained_D15 != "" else "",
1122
+ 1 if if_save_latest13 == True else 0,
1123
+ 1 if if_cache_gpu17 == True else 0,
1124
+ 1 if if_save_every_weights18 == True else 0,
1125
+ version19,
1126
+ )
1127
  )
1128
  yield get_info_str(cmd)
1129
  p = Popen(cmd, shell=True, cwd=now_dir)
 
1158
  yield get_info_str("adding index")
1159
  batch_size_add = 8192
1160
  for i in range(0, big_npy.shape[0], batch_size_add):
1161
+ index.add(big_npy[i: i + batch_size_add])
1162
  faiss.write_index(
1163
  index,
1164
  "%s/added_IVF%s_Flat_nprobe_%s_%s_%s.index"
 
1175
  mango = True if radio == 'mangio-crepe' or radio == 'mangio-crepe-tiny' else False
1176
  return ({"visible": mango, "__type__": "update"})
1177
 
1178
+
1179
  # ckpt_path2.change(change_info_,[ckpt_path2],[sr__,if_f0__])
1180
  def change_info_(ckpt_path):
1181
  if (
1182
+ os.path.exists(ckpt_path.replace(os.path.basename(ckpt_path), "train.log"))
1183
+ == False
1184
  ):
1185
  return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
1186
  try:
1187
  with open(
1188
+ ckpt_path.replace(os.path.basename(ckpt_path), "train.log"), "r"
1189
  ) as f:
1190
  info = eval(f.read().strip("\n").split("\n")[0].split("\t")[-1])
1191
  sr, f0 = info["sample_rate"], info["if_f0"]
 
1202
  def export_onnx(ModelPath, ExportedPath, MoeVS=True):
1203
  cpt = torch.load(ModelPath, map_location="cpu")
1204
  cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
1205
+ hidden_channels = 256 if cpt.get("version",
1206
+ "v1") == "v1" else 768 # cpt["config"][-2] # hidden_channels,为768Vec做准备
1207
 
1208
  test_phone = torch.rand(1, 200, hidden_channels) # hidden unit
1209
  test_phone_lengths = torch.tensor([200]).long() # hidden unit 长度(貌似没啥用)
 
1214
 
1215
  device = "cpu" # 导出时设备(不影响使用模型)
1216
 
 
1217
  net_g = SynthesizerTrnMsNSFsidM(
1218
+ *cpt["config"], is_half=False, version=cpt.get("version", "v1")
1219
  ) # fp32导出(C++要支持fp16必须手动将内存重新排列所以暂时不用fp16)
1220
  net_g.load_state_dict(cpt["weight"], strict=False)
1221
  input_names = ["phone", "phone_lengths", "pitch", "pitchf", "ds", "rnd"]
 
1248
  )
1249
  return "Finished"
1250
 
1251
+
1252
+ # region RVC WebUI App
1253
 
1254
  def get_presets():
1255
  data = None
 
1258
  preset_names = []
1259
  for preset in data['presets']:
1260
  preset_names.append(preset['name'])
1261
+
1262
  return preset_names
1263
 
1264
+
1265
  def change_choices2():
1266
+ audio_files = []
1267
  for filename in os.listdir("./audios"):
1268
+ if filename.endswith(('.wav', '.mp3', '.ogg', '.flac', '.m4a', '.aac', '.mp4')):
1269
+ audio_files.append(os.path.join('./audios', filename).replace('\\', '/'))
1270
  return {"choices": sorted(audio_files), "__type__": "update"}, {"__type__": "update"}
1271
+
1272
+
1273
+ audio_files = []
1274
  for filename in os.listdir("./audios"):
1275
+ if filename.endswith(('.wav', '.mp3', '.ogg', '.flac', '.m4a', '.aac', '.mp4')):
1276
+ audio_files.append(os.path.join('./audios', filename).replace('\\', '/'))
1277
+
1278
+
1279
  def get_index():
1280
  if check_for_name() != '':
1281
+ chosen_model = sorted(names)[0].split(".")[0]
1282
+ logs_path = "./logs/" + chosen_model
1283
  if os.path.exists(logs_path):
1284
  for file in os.listdir(logs_path):
1285
  if file.endswith(".index"):
 
1287
  return ''
1288
  else:
1289
  return ''
1290
+
1291
+
1292
  def get_indexes():
1293
+ indexes_list = []
1294
  for dirpath, dirnames, filenames in os.walk("./logs/"):
1295
  for filename in filenames:
1296
  if filename.endswith(".index"):
1297
+ indexes_list.append(os.path.join(dirpath, filename))
1298
  if len(indexes_list) > 0:
1299
  return indexes_list
1300
  else:
1301
  return ''
1302
+
1303
+
1304
  def get_name():
1305
  if len(audio_files) > 0:
1306
  return sorted(audio_files)[0]
1307
  else:
1308
  return ''
1309
+
1310
+
1311
  def save_to_wav(record_button):
1312
  if record_button is None:
1313
  pass
1314
  else:
1315
+ path_to_file = record_button
1316
+ new_name = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + '.wav'
1317
+ new_path = './audios/' + new_name
1318
+ shutil.move(path_to_file, new_path)
1319
  return new_path
1320
+
1321
+
1322
  def save_to_wav2(dropbox):
1323
+ file_path = dropbox.name
1324
+ shutil.move(file_path, './audios')
1325
+ return os.path.join('./audios', os.path.basename(file_path))
1326
+
1327
+
1328
  def match_index(sid0):
1329
+ folder = sid0.split(".")[0]
1330
+ parent_dir = "./logs/" + folder
1331
  if os.path.exists(parent_dir):
1332
  for filename in os.listdir(parent_dir):
1333
  if filename.endswith(".index"):
1334
+ index_path = os.path.join(parent_dir, filename)
1335
  return index_path
1336
  else:
1337
  return ''
1338
+
1339
+
1340
  def check_for_name():
1341
  if len(names) > 0:
1342
  return sorted(names)[0]
1343
  else:
1344
  return ''
1345
+
1346
+
1347
  def download_from_url(url, model):
1348
  if url == '':
1349
  return "URL cannot be left empty."
1350
+ if model == '':
1351
  return "You need to name your model. For example: My-Model"
1352
  url = url.strip()
1353
  zip_dirs = ["zips", "unzips"]
 
1368
  subprocess.run(["wget", url, "-O", zipfile_path])
1369
  for filename in os.listdir("./zips"):
1370
  if filename.endswith(".zip"):
1371
+ zipfile_path = os.path.join("./zips/", filename)
1372
  shutil.unpack_archive(zipfile_path, "./unzips", 'zip')
1373
  else:
1374
  return "No zipfile found."
 
1377
  file_path = os.path.join(root, file)
1378
  if file.endswith(".index"):
1379
  os.mkdir(f'./logs/{model}')
1380
+ shutil.copy2(file_path, f'./logs/{model}')
1381
  elif "G_" not in file and "D_" not in file and file.endswith(".pth"):
1382
+ shutil.copy(file_path, f'./weights/{model}.pth')
1383
  shutil.rmtree("zips")
1384
  shutil.rmtree("unzips")
1385
  return "Success."
1386
  except:
1387
  return "There's been an error."
1388
+
1389
+
1390
  def success_message(face):
1391
  return f'{face.name} has been uploaded.', 'None'
1392
+
1393
+
1394
  def mouth(size, face, voice, faces):
1395
  if size == 'Half':
1396
  size = 2
 
1404
  elif faces == 'Andrew Tate':
1405
  character = '/content/wav2lip-HD/inputs/tate-7.mp4'
1406
  command = "python inference.py " \
1407
+ "--checkpoint_path checkpoints/wav2lip.pth " \
1408
+ f"--face {character} " \
1409
+ f"--audio {voice} " \
1410
+ "--pads 0 20 0 0 " \
1411
+ "--outfile /content/wav2lip-HD/outputs/result.mp4 " \
1412
+ "--fps 24 " \
1413
+ f"--resize_factor {size}"
1414
  process = subprocess.Popen(command, shell=True, cwd='/content/wav2lip-HD/Wav2Lip-master')
1415
  stdout, stderr = process.communicate()
1416
  return '/content/wav2lip-HD/outputs/result.mp4', 'Animation completed.'
1417
+
1418
+
1419
+ eleven_voices = ['Adam', 'Antoni', 'Josh', 'Arnold', 'Sam', 'Bella', 'Rachel', 'Domi', 'Elli']
1420
+ eleven_voices_ids = ['pNInz6obpgDQGcFmaJgB', 'ErXwobaYiN019PkySvjV', 'TxGEqnHWrfWFTfGW9XjX', 'VR6AewLTigWG4xSOukaG',
1421
+ 'yoZ06aMxZJJ28mfd3POQ', 'EXAVITQu4vr4xnSDxMaL', '21m00Tcm4TlvDq8ikWAM', 'AZnzlk1XvdvUeBnXmlld',
1422
+ 'MF3mGyEYCl7XYWbV9V6O']
1423
  chosen_voice = dict(zip(eleven_voices, eleven_voices_ids))
1424
 
1425
+
1426
+ def stoptraining(mim):
1427
  if int(mim) == 1:
1428
  try:
1429
  CSVutil('csvdb/stop.csv', 'w+', 'stop', 'True')
 
1431
  except Exception as e:
1432
  print(f"Couldn't click due to {e}")
1433
  return (
1434
+ {"visible": False, "__type__": "update"},
1435
  {"visible": True, "__type__": "update"},
1436
  )
1437
 
1438
 
1439
  def elevenTTS(xiapi, text, id, lang):
1440
+ if xiapi != '' and id != '':
1441
  choice = chosen_voice[id]
1442
  CHUNK_SIZE = 1024
1443
  url = f"https://api.elevenlabs.io/v1/text-to-speech/{choice}"
1444
  headers = {
1445
+ "Accept": "audio/mpeg",
1446
+ "Content-Type": "application/json",
1447
+ "xi-api-key": xiapi
1448
  }
1449
  if lang == 'en':
1450
  data = {
1451
+ "text": text,
1452
+ "model_id": "eleven_monolingual_v1",
1453
+ "voice_settings": {
1454
+ "stability": 0.5,
1455
+ "similarity_boost": 0.5
1456
+ }
1457
  }
1458
  else:
1459
  data = {
1460
+ "text": text,
1461
+ "model_id": "eleven_multilingual_v1",
1462
+ "voice_settings": {
1463
+ "stability": 0.5,
1464
+ "similarity_boost": 0.5
1465
+ }
1466
  }
1467
 
1468
  response = requests.post(url, json=data, headers=headers)
1469
  with open('./temp_eleven.mp3', 'wb') as f:
1470
+ for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
1471
+ if chunk:
1472
+ f.write(chunk)
1473
  aud_path = save_to_wav('./temp_eleven.mp3')
1474
  return aud_path, aud_path
1475
  else:
 
1478
  aud_path = save_to_wav('./temp_gTTS.mp3')
1479
  return aud_path, aud_path
1480
 
1481
+
1482
  def upload_to_dataset(files, dir):
1483
  if dir == '':
1484
  dir = './dataset'
 
1486
  os.makedirs(dir)
1487
  count = 0
1488
  for file in files:
1489
+ path = file.name
1490
+ shutil.copy2(path, dir)
1491
  count += 1
1492
+ return f' {count} files uploaded to {dir}.'
1493
+
1494
+
1495
  def zip_downloader(model):
1496
  if not os.path.exists(f'./weights/{model}.pth'):
1497
  return {"__type__": "update"}, f'Make sure the Voice Name is correct. I could not find {model}.pth'
 
1505
  else:
1506
  return f'./weights/{model}.pth', "Could not find Index file."
1507
 
1508
+
1509
  with gr.Blocks(theme=gr.themes.Base(), title='Voice DeepFake 💻') as app:
1510
+ # gr.LogoutButton()
1511
  with gr.Tabs():
1512
  with gr.TabItem("Interfeys"):
1513
+ gr.HTML("<center><h1> Voice DeepFake </h1></span>")
1514
  # gr.HTML("<center><h3> Если вы хотите использовать это пространство в частном порядке, я рекомендую продублировать его. </h3></span>")
1515
  # with gr.Row():
1516
  # gr.Markdown(
 
1533
  refresh_button = gr.Button("Yangilash", variant="primary")
1534
  if check_for_name() != '':
1535
  get_vc(sorted(names)[0])
1536
+ vc_transform0 = gr.Number(
1537
+ label="Kengaytirilgan: Bu yerda siz ovoz balandligini o'zgartirishingiz yoki uni 0 da qoldirishingiz mumkin.",
1538
+ value=0)
1539
+ # clean_button = gr.Button(i18n("卸载音色省显存"), variant="primary")
1540
  spk_item = gr.Slider(
1541
  minimum=0,
1542
  maximum=2333,
 
1546
  visible=False,
1547
  interactive=True,
1548
  )
1549
+ # clean_button.click(fn=clean, inputs=[], outputs=[sid0])
1550
  sid0.change(
1551
  fn=get_vc,
1552
  inputs=[sid0],
 
1556
  with gr.Row():
1557
  with gr.Column():
1558
  with gr.Row():
1559
+ dropbox = gr.File(
1560
+ label='Ovoz yozishingizni shu yerga yuboring va "Qayta yuklash" tugmasini bosing.')
1561
  with gr.Row():
1562
+ record_button = gr.Audio(source="microphone", label="Ovozni mikrofondan yozib oling.",
1563
+ type="filepath")
1564
  with gr.Row():
1565
  input_audio0 = gr.Dropdown(
1566
  label="2.Audio yozuvni tanlang.",
1567
  value="./audios/someguy.mp3",
1568
  choices=audio_files
1569
+ )
1570
  dropbox.upload(fn=save_to_wav2, inputs=[dropbox], outputs=[input_audio0])
1571
  dropbox.upload(fn=change_choices2, inputs=[], outputs=[input_audio0])
1572
  refresh_button2 = gr.Button("Yangilash", variant="primary", size='sm')
 
1584
  with gr.Row():
1585
  with gr.Accordion('Wav2Lip', open=False, visible=False):
1586
  with gr.Row():
1587
+ size = gr.Radio(label='Resolution:', choices=['Half', 'Full'])
1588
+ face = gr.UploadButton("Upload A Character", type='file')
1589
+ faces = gr.Dropdown(label="OR Choose one:",
1590
+ choices=['None', 'Ben Shapiro', 'Andrew Tate'])
1591
  with gr.Row():
1592
+ preview = gr.Textbox(label="Status:", interactive=False)
1593
+ face.upload(fn=success_message, inputs=[face], outputs=[preview, faces])
1594
  with gr.Row():
1595
  animation = gr.Video(type='filepath')
1596
  refresh_button2.click(fn=change_choices2, inputs=[], outputs=[input_audio0, animation])
 
1604
  choices=get_indexes(),
1605
  value=get_index(),
1606
  interactive=True,
1607
+ )
1608
+ sid0.change(fn=match_index, inputs=[sid0], outputs=[file_index1])
1609
  refresh_button.click(
1610
  fn=change_choices, inputs=[], outputs=[sid0, file_index1]
1611
+ )
1612
  # file_big_npy1 = gr.Textbox(
1613
  # label=i18n("特征文件路径"),
1614
  # value="E:\\codes\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
 
1620
  label=i18n("Qidiruv funksiyasining nisbati (men uni 0 ga o'rnatishni tavsiya qilaman):"),
1621
  value=0.66,
1622
  interactive=True,
1623
+ )
1624
  vc_output2 = gr.Audio(
1625
  label="Audio ma'lumotlarni chiqarish (yuklab olish uchun o'ng burchakdagi uchta nuqta ustiga bosing)",
1626
  type='filepath',
 
1630
  with gr.Accordion("Qo'shimcha sozlamalar", open=False):
1631
  f0method0 = gr.Radio(
1632
  label='Majburiy emas: Ovozni ajratib olish algoritmini o\'zgartiring.',
1633
+ choices=["pm", "dio", "crepe-tiny", "mangio-crepe-tiny", "crepe", "harvest", "mangio-crepe",
1634
+ "rmvpe"], # Fork Feature. Add Crepe-Tiny
1635
  value="rmvpe",
1636
  interactive=True,
1637
  )
1638
+
1639
  crepe_hop_length = gr.Slider(
1640
  minimum=1,
1641
  maximum=512,
 
1644
  value=120,
1645
  interactive=True,
1646
  visible=False,
1647
+ )
1648
  f0method0.change(fn=whethercrepeornah, inputs=[f0method0], outputs=[crepe_hop_length])
1649
  filter_radius0 = gr.Slider(
1650
  minimum=0,
1651
  maximum=7,
1652
+ label=i18n(
1653
+ "Agar >=3 boʻlsa: toʻplangan ovoz balandligi natijalariga median filtrlashni qoʻllang. Qiymat filtrlash radiusini ifodalaydi va nafas olishni qisqartirishi mumkin"),
1654
  value=3,
1655
  step=1,
1656
  interactive=True,
1657
+ )
1658
  resample_sr0 = gr.Slider(
1659
  minimum=0,
1660
  maximum=48000,
 
1663
  step=1,
1664
  interactive=True,
1665
  visible=False
1666
+ )
1667
  rms_mix_rate0 = gr.Slider(
1668
  minimum=0,
1669
  maximum=1,
1670
+ label=i18n(
1671
+ "Chiqish ovozi konvertini almashtirish yoki aralashtirish uchun kirish ovozi konvertidan foydalaning. Bu nisbat 1 ga qanchalik yaqin bo'lsa, chiqish signali konvertidan shunchalik ko'p foydalaniladi:"),
1672
  value=0.21,
1673
  interactive=True,
1674
+ )
1675
  protect0 = gr.Slider(
1676
  minimum=0,
1677
  maximum=0.5,
1678
+ label=i18n(
1679
+ "Elektron musiqadagi tanaffuslar kabi artefaktlarning oldini olish uchun ovozsiz undosh tovushlarni va nafas tovushlarini himoya qiladi. O'chirish uchun qiymatni 0,5 ga o'rnating. Xavfsizlikni oshirish uchun qiymatni kamaytiring, lekin bu indekslash aniqligini kamaytirishi mumkin:"),
1680
  value=0.33,
1681
  step=0.01,
1682
  interactive=True,
1683
+ )
1684
  formanting = gr.Checkbox(
1685
  value=bool(DoFormant),
1686
  label="[EXPERIMENTAL] Formant shift inference audio",
 
1688
  interactive=True,
1689
  visible=False,
1690
  )
1691
+
1692
  formant_preset = gr.Dropdown(
1693
  value='',
1694
  choices=get_fshift_presets(),
 
1700
  visible=bool(DoFormant),
1701
  variant='primary',
1702
  )
1703
+ # formant_refresh_button = ToolButton( elem_id='1')
1704
+ # create_refresh_button(formant_preset, lambda: {"choices": formant_preset}, "refresh_list_shiftpresets")
1705
+
1706
  qfrency = gr.Slider(
1707
+ value=Quefrency,
1708
+ info="Default value is 1.0",
1709
+ label="Quefrency for formant shifting",
1710
+ minimum=0.0,
1711
+ maximum=16.0,
1712
+ step=0.1,
1713
+ visible=bool(DoFormant),
1714
+ interactive=True,
1715
+ )
1716
  tmbre = gr.Slider(
1717
  value=Timbre,
1718
  info="Default value is 1.0",
 
1723
  visible=bool(DoFormant),
1724
  interactive=True,
1725
  )
1726
+
1727
+ formant_preset.change(fn=preset_apply, inputs=[formant_preset, qfrency, tmbre],
1728
+ outputs=[qfrency, tmbre])
1729
  frmntbut = gr.Button("Apply", variant="primary", visible=bool(DoFormant))
1730
+ formanting.change(fn=formant_enabled,
1731
+ inputs=[formanting, qfrency, tmbre, frmntbut, formant_preset,
1732
+ formant_refresh_button],
1733
+ outputs=[formanting, qfrency, tmbre, frmntbut, formant_preset,
1734
+ formant_refresh_button])
1735
+ frmntbut.click(fn=formant_apply, inputs=[qfrency, tmbre], outputs=[qfrency, tmbre])
1736
+ formant_refresh_button.click(fn=update_fshift_presets, inputs=[formant_preset, qfrency, tmbre],
1737
+ outputs=[formant_preset, qfrency, tmbre])
1738
  with gr.Row():
1739
  vc_output1 = gr.Textbox("")
1740
  f0_file = gr.File(label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调"), visible=False)
1741
+
1742
  but0.click(
1743
  vc_single,
1744
  [
 
1759
  ],
1760
  [vc_output1, vc_output2],
1761
  )
1762
+
1763
+ with gr.Accordion("Batch Conversion", open=False, visible=False):
1764
  with gr.Row():
1765
  with gr.Column():
1766
  vc_transform1 = gr.Number(
 
1885
  # """
1886
  # )
1887
  with gr.Row():
1888
+ url = gr.Textbox(label="Model URL manzilini kiriting:",
1889
+ placeholder=".pth va .index fayllarni o'z ichiga olgan zipga havolani kiriting")
1890
  with gr.Row():
1891
  model = gr.Textbox(label="Model nomi:")
1892
+ download_button = gr.Button("Yuklash")
1893
  with gr.Row():
1894
+ status_bar = gr.Textbox(label="")
1895
  download_button.click(fn=download_from_url, inputs=[url, model], outputs=[status_bar])
1896
 
1897
+
1898
  def has_two_files_in_pretrained_folder():
1899
  pretrained_folder = "./pretrained/"
1900
  if not os.path.exists(pretrained_folder):
 
1904
  num_files = len(files_in_folder)
1905
  return num_files >= 2
1906
 
1907
+
1908
+ if has_two_files_in_pretrained_folder():
1909
+ print("Pretrained weights are downloaded. Training tab enabled!\n-------------------------------")
1910
  with gr.TabItem("Train", visible=False):
1911
  with gr.Row():
1912
  with gr.Column():
 
1942
  visible=True
1943
  )
1944
  trainset_dir4 = gr.Textbox(label="Path to your dataset (audios, not zip):", value="./dataset")
1945
+ easy_uploader = gr.Files(
1946
+ label='OR Drop your audios here. They will be uploaded in your dataset path above.',
1947
+ file_types=['audio'])
1948
  but1 = gr.Button("1. Process The Dataset", variant="primary")
1949
  info1 = gr.Textbox(label="Status (wait until it says 'end preprocess'):", value="")
1950
+ easy_uploader.upload(fn=upload_to_dataset, inputs=[easy_uploader, trainset_dir4],
1951
+ outputs=[info1])
1952
  but1.click(
1953
  preprocess_dataset, [trainset_dir4, exp_dir1, sr2, np7], [info1]
1954
  )
 
1974
  label=i18n(
1975
  "选择音高提取算法:输入歌声可用pm提速,高质量语音但CPU差可用dio提速,harvest质量更好但慢"
1976
  ),
1977
+ choices=["harvest", "crepe", "mangio-crepe", "rmvpe"],
1978
+ # Fork feature: Crepe on f0 extraction for training.
1979
  value="rmvpe",
1980
  interactive=True,
1981
  )
1982
+
1983
  extraction_crepe_hop_length = gr.Slider(
1984
  minimum=1,
1985
  maximum=512,
 
1989
  interactive=True,
1990
  visible=False,
1991
  )
1992
+ f0method8.change(fn=whethercrepeornah, inputs=[f0method8],
1993
+ outputs=[extraction_crepe_hop_length])
1994
  but2 = gr.Button("2. Pitch Extraction", variant="primary")
1995
+ info2 = gr.Textbox(label="Status(Check the Colab Notebook's cell output):", value="",
1996
+ max_lines=8)
1997
  but2.click(
1998
+ extract_f0_feature,
1999
+ [gpus6, np7, f0method8, if_f0_3, exp_dir1, version19, extraction_crepe_hop_length],
2000
+ [info2],
2001
+ )
2002
+ with gr.Row():
2003
  with gr.Column():
2004
  total_epoch11 = gr.Slider(
2005
  minimum=1,
 
2015
  visible=False,
2016
  )
2017
  but3 = gr.Button("3. Train Model", variant="primary", visible=True)
2018
+
2019
+ but3.click(fn=stoptraining, inputs=[gr.Number(value=0, visible=False)],
2020
+ outputs=[but3, butstop])
2021
+ butstop.click(fn=stoptraining, inputs=[gr.Number(value=1, visible=False)],
2022
+ outputs=[butstop, but3])
2023
+
2024
  but4 = gr.Button("4.Train Index", variant="primary")
2025
+ info3 = gr.Textbox(label="Status(Check the Colab Notebook's cell output):", value="",
2026
+ max_lines=10)
2027
  with gr.Accordion("Training Preferences (You can leave these as they are)", open=False):
2028
+ # gr.Markdown(value=i18n("step3: 填写训练设置, 开始训练模型和索引"))
2029
  with gr.Column():
2030
  save_epoch10 = gr.Slider(
2031
  minimum=1,
 
2144
  info3,
2145
  )
2146
 
 
 
 
 
 
 
 
 
2147
  app.queue(concurrency_count=511, max_size=1022).launch(auth=("admin", "admin"), share=False, quiet=True)
2148
+ # endregion
i18n/uz_UZ.json CHANGED
@@ -2,8 +2,8 @@
2
  "Unfortunately, you do not have a working graphics card to support your training": "Afsuski, mashg'ulotingizni qo'llab-quvvatlash uchun mos keladigan GPU mavjud emas.",
3
  "是": "Ha",
4
  "step1:processing data": "1-qadam: Ma'lumotlarni qayta ishlash",
5
- "step2a: No need to extract the pitch": "2a-qadam: Ohangni chiqarishni o'tkazib yuborish",
6
- "step2b:Extracting features": "2b-qadam: Xususiyatlarni ajratib olish",
7
  "step3a:正在训练模型": "3a qadam: Modelni o'qitish boshlandi",
8
  "训练结束, 您可查看控制台训练日志或实验文件夹下的train.log": "O'qish yakunlandi. O'quv jurnalini konsolda yoki eksperiment jildi ichidagi 'train.log' faylida tekshirishingiz mumkin.",
9
  "全流程结束!": "Barcha jarayonlar bajarildi!",
 
2
  "Unfortunately, you do not have a working graphics card to support your training": "Afsuski, mashg'ulotingizni qo'llab-quvvatlash uchun mos keladigan GPU mavjud emas.",
3
  "是": "Ha",
4
  "step1:processing data": "1-qadam: Ma'lumotlarni qayta ishlash",
5
+ "step2a:无需提取音高": "2a-qadam: Ohangni chiqarishni o'tkazib yuborish",
6
+ "step2b:正在提取特征": "2b-qadam: Xususiyatlarni ajratib olish",
7
  "step3a:正在训练模型": "3a qadam: Modelni o'qitish boshlandi",
8
  "训练结束, 您可查看控制台训练日志或实验文件夹下的train.log": "O'qish yakunlandi. O'quv jurnalini konsolda yoki eksperiment jildi ichidagi 'train.log' faylida tekshirishingiz mumkin.",
9
  "全流程结束!": "Barcha jarayonlar bajarildi!",