ArianatorQualquer commited on
Commit
291b39f
·
1 Parent(s): 574a0a6

Delete Run.py

Browse files
Files changed (1) hide show
  1. Run.py +0 -160
Run.py DELETED
@@ -1,160 +0,0 @@
1
- import argparse
2
- import hashlib
3
- import os
4
- import yt_dlp
5
- import gc
6
-
7
- import json
8
-
9
- BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))
10
-
11
- mdxnet_models_dir = os.path.join(BASE_DIR, 'mdxnet_models')
12
- rvc_models_dir = os.path.join(BASE_DIR, 'rvc_models')
13
- output_dir = os.path.join(BASE_DIR, 'song_output')
14
-
15
-
16
- def get_youtube_video_id(url, ignore_playlist=True):
17
- # Função para obter o ID de um vídeo do YouTube a partir de uma URL
18
- # ...
19
-
20
-
21
- def yt_download(link):
22
- # Função para fazer o download de um vídeo do YouTube
23
- # ...
24
-
25
-
26
- def raise_exception(error_msg, is_webui):
27
- # Função para lançar exceção
28
- # ...
29
-
30
-
31
- def get_rvc_model(voice_model, is_webui):
32
- # Função para obter o modelo RVC
33
- # ...
34
-
35
-
36
- def get_audio_paths(song_dir):
37
- # Função para obter os caminhos dos arquivos de áudio
38
- # ...
39
-
40
-
41
- def get_hash(filepath):
42
- # Função para calcular o hash de um arquivo
43
- # ...
44
-
45
-
46
- def display_progress(message, percent, is_webui, progress=None):
47
- # Função para exibir o progresso
48
- # ...
49
-
50
-
51
- def preprocess_song(song_input, mdx_model_params, song_id, is_webui, input_type, progress=None):
52
- # Função para o pré-processamento da música
53
- # ...
54
-
55
-
56
- def voice_change(voice_model, vocals_path, output_path, pitch_change, f0_method, index_rate, filter_radius, rms_mix_rate, protect, crepe_hop_length, is_webui):
57
- # Função para realizar a inferência de voz com o modelo RVC
58
- # ...
59
-
60
-
61
- def song_cover_pipeline(song_input, voice_model, pitch_change, keep_files,
62
- is_webui=0, main_gain=0, backup_gain=0, inst_gain=0, index_rate=0.5, filter_radius=3,
63
- rms_mix_rate=0.25, f0_method='rmvpe', crepe_hop_length=128, protect=0.33, pitch_change_all=0,
64
- reverb_rm_size=0.15, reverb_wet=0.2, reverb_dry=0.8, reverb_damping=0.7, output_format='mp3',
65
- progress=None):
66
- try:
67
- if not song_input or not voice_model:
68
- raise_exception('Ensure that the song input field and voice model field is filled.', is_webui)
69
-
70
- display_progress('[~] Starting AI Cover Generation Pipeline...', 0, is_webui, progress)
71
-
72
- with open(os.path.join(mdxnet_models_dir, 'model_data.json')) as infile:
73
- mdx_model_params = json.load(infile)
74
-
75
- # if youtube url
76
- if urlparse(song_input).scheme == 'https':
77
- input_type = 'yt'
78
- song_id = get_youtube_video_id(song_input)
79
- if song_id is None:
80
- error_msg = 'Invalid YouTube url.'
81
- raise_exception(error_msg, is_webui)
82
-
83
- # local audio file
84
- else:
85
- input_type = 'local'
86
- song_input = song_input.strip('\"')
87
- if os.path.exists(song_input):
88
- song_id = get_hash(song_input)
89
- else:
90
- error_msg = f'{song_input} does not exist.'
91
- song_id = None
92
- raise_exception(error_msg, is_webui)
93
-
94
- song_dir = os.path.join(output_dir, song_id)
95
-
96
- if not os.path.exists(song_dir):
97
- os.makedirs(song_dir)
98
- orig_song_path = song_input
99
-
100
- else:
101
- orig_song_path = os.path.join(song_dir, f'{song_id}.mp3')
102
-
103
- pitch_change = pitch_change * 12 + pitch_change_all
104
- ai_vocals_path = os.path.join(song_dir, f'{os.path.splitext(os.path.basename(orig_song_path))[0]}_{voice_model}_p{pitch_change}_i{index_rate}_fr{filter_radius}_rms{rms_mix_rate}_pro{protect}_{f0_method}{"" if f0_method != "mangio-crepe" else f"_{crepe_hop_length}"}.wav')
105
- ai_cover_path = os.path.join(song_dir, f'{os.path.splitext(os.path.basename(orig_song_path))[0]} ({voice_model} Ver).{output_format}')
106
-
107
- if not os.path.exists(ai_vocals_path):
108
- display_progress('[~] Converting voice using RVC...', 0.5, is_webui, progress)
109
- voice_change(voice_model, orig_song_path, ai_vocals_path, pitch_change, f0_method, index_rate, filter_radius, rms_mix_rate, protect, crepe_hop_length, is_webui)
110
-
111
- if not keep_files:
112
- display_progress('[~] Removing intermediate audio files...', 0.95, is_webui, progress)
113
- intermediate_files = [orig_song_path]
114
- for file in intermediate_files:
115
- if file and os.path.exists(file):
116
- os.remove(file)
117
-
118
- return ai_cover_path
119
-
120
- except Exception as e:
121
- raise_exception(str(e), is_webui)
122
-
123
-
124
- if __name__ == '__main__':
125
- parser = argparse.ArgumentParser(description='Generate a AI cover song in the song_output/id directory.', add_help=True)
126
- parser.add_argument('-i', '--song-input', type=str, required=True, help='Link to a YouTube video or the filepath to a local mp3/wav file to create an AI cover of')
127
- parser.add_argument('-dir', '--rvc-dirname', type=str, required=True, help='Name of the folder in the rvc_models directory containing the RVC model file and optional index file to use')
128
- parser.add_argument('-p', '--pitch-change', type=int, required=True, help='Change the pitch of AI Vocals only. Generally, use 1 for male to female and -1 for vice-versa. (Octaves)')
129
- parser.add_argument('-k', '--keep-files', action=argparse.BooleanOptionalAction, help='Whether to keep all intermediate audio files generated in the song_output/id directory, e.g. Isolated Vocals/Instrumentals')
130
- parser.add_argument('-ir', '--index-rate', type=float, default=0.5, help='A decimal number e.g. 0.5, used to reduce/resolve the timbre leakage problem. If set to 1, more biased towards the timbre quality of the training dataset')
131
- parser.add_argument('-fr', '--filter-radius', type=int, default=3, help='A number between 0 and 7. If >=3: apply median filtering to the harvested pitch results. The value represents the filter radius and can reduce breathiness.')
132
- parser.add_argument('-rms', '--rms-mix-rate', type=float, default=0.25, help="A decimal number e.g. 0.25. Control how much to use the original vocal's loudness (0) or a fixed loudness (1).")
133
- parser.add_argument('-palgo', '--pitch-detection-algo', type=str, default='rmvpe', help='Best option is rmvpe (clarity in vocals), then mangio-crepe (smoother vocals).')
134
- parser.add_argument('-hop', '--crepe-hop-length', type=int, default=128, help='If pitch detection algo is mangio-crepe, controls how often it checks for pitch changes in milliseconds. The higher the value, the faster the conversion and less risk of voice cracks, but there is less pitch accuracy. Recommended: 128.')
135
- parser.add_argument('-pro', '--protect', type=float, default=0.33, help='A decimal number e.g. 0.33. Protect voiceless consonants and breath sounds to prevent artifacts such as tearing in electronic music. Set to 0.5 to disable. Decrease the value to increase protection, but it may reduce indexing accuracy.')
136
- parser.add_argument('-mv', '--main-vol', type=int, default=0, help='Volume change for AI main vocals in decibels. Use -3 to decrease by 3 decibels and 3 to increase by 3 decibels')
137
- parser.add_argument('-bv', '--backup-vol', type=int, default=0, help='Volume change for backup vocals in decibels')
138
- parser.add_argument('-iv', '--inst-vol', type=int, default=0, help='Volume change for instrumentals in decibels')
139
- parser.add_argument('-pall', '--pitch-change-all', type=int, default=0, help='Change the pitch/key of vocals and instrumentals. Changing this slightly reduces sound quality')
140
- parser.add_argument('-rsize', '--reverb-size', type=float, default=0.15, help='Reverb room size between 0 and 1')
141
- parser.add_argument('-rwet', '--reverb-wetness', type=float, default=0.2, help='Reverb wet level between 0 and 1')
142
- parser.add_argument('-rdry', '--reverb-dryness', type=float, default=0.8, help='Reverb dry level between 0 and 1')
143
- parser.add_argument('-rdamp', '--reverb-damping', type=float, default=0.7, help='Reverb damping between 0 and 1')
144
- parser.add_argument('-oformat', '--output-format', type=str, default='mp3', help='Output format of audio file. mp3 for smaller file size, wav for best quality')
145
- args = parser.parse_args()
146
-
147
- rvc_dirname = args.rvc_dirname
148
- if not os.path.exists(os.path.join(rvc_models_dir, rvc_dirname)):
149
- raise Exception(f'The folder {os.path.join(rvc_models_dir, rvc_dirname)} does not exist.')
150
-
151
- cover_path = song_cover_pipeline(args.song_input, rvc_dirname, args.pitch_change, args.keep_files,
152
- main_gain=args.main_vol, backup_gain=args.backup_vol, inst_gain=args.inst_vol,
153
- index_rate=args.index_rate, filter_radius=args.filter_radius,
154
- rms_mix_rate=args.rms_mix_rate, f0_method=args.pitch_detection_algo,
155
- crepe_hop_length=args.crepe_hop_length, protect=args.protect,
156
- pitch_change_all=args.pitch_change_all,
157
- reverb_rm_size=args.reverb_size, reverb_wet=args.reverb_wetness,
158
- reverb_dry=args.reverb_dryness, reverb_damping=args.reverb_damping,
159
- output_format=args.output_format)
160
- print(f'[+] Cover generated at {cover_path}')