Nah_kagz1092 commited on
Commit
1d74c6a
·
verified ·
1 Parent(s): 0f97e7e

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +86 -0
main.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from voice_changer.RVC.RVCModelSlotGenerator import RVCModelSlotGenerator
2
+ from voice_changer.VoiceChangerParamsManager import VoiceChangerParamsManager
3
+ from voice_changer.utils.LoadModelParams import LoadModelParamFile, LoadModelParams
4
+ from voice_changer.utils.VoiceChangerParams import VoiceChangerParams
5
+ model_dir1 = "model_dir/"+model_slot+"/"
6
+ is_pth = True # Set this to True if you want to search for .pth files, or False for .onnx files
7
+ file_extension = ".pth" if is_pth else ".onnx"
8
+ # pth_files = [f for f in os.listdir(model_dir1) if f.endswith(file_extension)]
9
+ pth_files = [f for f in os.listdir(model_dir1) if f.endswith(".pth") or f.endswith(".onnx")]
10
+ print(pth_files)
11
+ index_files = [f for f in os.listdir(model_dir1) if f.endswith(".index")]
12
+ if pth_files:
13
+ model_name = pth_files[0].replace(".pth", "")
14
+ else:
15
+ model_name = "Null"
16
+ if index_files:
17
+ index_name = index_files[0].replace(".index", "")
18
+ else:
19
+ index_name = ""
20
+ original_string = str(pth_files)
21
+ string_pth_files = original_string[2:-2]
22
+ print("IM A STRING"+original_string)
23
+ print(model_name)
24
+ voiceChangerParams = VoiceChangerParams(
25
+ model_dir="./model_dir/"+model_slot,
26
+ content_vec_500="",
27
+ content_vec_500_onnx="",
28
+ content_vec_500_onnx_on="",
29
+ hubert_base="",
30
+ hubert_base_jp="",
31
+ hubert_soft="",
32
+ nsf_hifigan="",
33
+ crepe_onnx_full="",
34
+ crepe_onnx_tiny="",
35
+ rmvpe="",
36
+ rmvpe_onnx="",
37
+ sample_mode=""
38
+ )
39
+ vcparams = VoiceChangerParamsManager.get_instance()
40
+ vcparams.setParams(voiceChangerParams)
41
+ file = LoadModelParamFile(
42
+ name=string_pth_files,
43
+ kind="rvcModel",
44
+ dir="",
45
+ )
46
+ loadParam = LoadModelParams(
47
+ voiceChangerType="RVC",
48
+ files=[file],
49
+ slot="",
50
+ isSampleMode=False,
51
+ sampleId="",
52
+ params={},
53
+ )
54
+ slotInfo = RVCModelSlotGenerator.loadModel(loadParam)
55
+ print(slotInfo.samplingRate)
56
+ #---------------Make the Json File-----------
57
+ params_content = {
58
+ "slotIndex": -1,
59
+ "voiceChangerType": "RVC",
60
+ "name": model_name,
61
+ "description": "",
62
+ "credit": "",
63
+ "termsOfUseUrl": "",
64
+ "iconFile": iconFile,
65
+ "speakers": {
66
+ "0": "target"
67
+ },
68
+ "modelFile": string_pth_files,
69
+ "indexFile": f"{index_name}.index",
70
+ "defaultTune": Tune,
71
+ "defaultIndexRatio": Index,
72
+ "defaultProtect": 0.5,
73
+ "isONNX": False,
74
+ "modelType": "pyTorchRVCv2",
75
+ "samplingRate": slotInfo.samplingRate,
76
+ "f0": True,
77
+ "embChannels": 768,
78
+ "embOutputLayer": 12,
79
+ "useFinalProj": False,
80
+ "deprecated": False,
81
+ "embedder": "hubert_base",
82
+ "sampleId": ""
83
+ }
84
+ # Write the content to params.json
85
+ with open(f"{model_dir1}/params.json", "w") as param_file:
86
+ json.dump(params_content, param_file)