File size: 6,321 Bytes
c8be32d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import argparse

from backend.generate_song_cover import run_pipeline

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Generate a cover song in the song_output/id directory.",
        add_help=True,
    )
    parser.add_argument(
        "-i",
        "--song-input",
        type=str,
        required=True,
        help=(
            "Link to a song on YouTube, the full path of a local audio file or a cached"
            " input song"
        ),
    )
    parser.add_argument(
        "-dir",
        "--rvc-dirname",
        type=str,
        required=True,
        help=(
            "Name of the folder in the models/rvc directory containing the RVC model"
            " file and optional index file to use"
        ),
    )
    parser.add_argument(
        "-pv",
        "--pitch-change-vocals",
        type=int,
        required=True,
        help=(
            "Shift the pitch of converted vocals only. Measured in octaves. Generally,"
            " use 1 for male to female and -1 for vice-versa."
        ),
    )
    parser.add_argument(
        "-pall",
        "--pitch-change-all",
        type=int,
        default=0,
        help=(
            "Shift pitch of converted vocals, backup vocals and instrumentals. Measured"
            " in semi-tones. Altering this slightly reduces sound quality"
        ),
    )
    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"
        ),
    )
    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."
        ),
    )
    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 loudness of the"
            " input vocals (0) or a fixed loudness (1)."
        ),
    )
    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."
        ),
    )
    parser.add_argument(
        "-palgo",
        "--pitch-detection-algo",
        type=str,
        default="rmvpe",
        help=(
            "Best option is rmvpe (clarity in vocals), then mangio-crepe (smoother"
            " vocals)."
        ),
    )
    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."
        ),
    )
    parser.add_argument(
        "-rsize",
        "--reverb-size",
        type=float,
        default=0.15,
        help="Reverb room size between 0 and 1",
    )
    parser.add_argument(
        "-rwet",
        "--reverb-wetness",
        type=float,
        default=0.2,
        help="Reverb wet level between 0 and 1",
    )
    parser.add_argument(
        "-rdry",
        "--reverb-dryness",
        type=float,
        default=0.8,
        help="Reverb dry level between 0 and 1",
    )
    parser.add_argument(
        "-rdamp",
        "--reverb-damping",
        type=float,
        default=0.7,
        help="Reverb damping between 0 and 1",
    )
    parser.add_argument(
        "-mv",
        "--main-vol",
        type=int,
        default=0,
        help=(
            "Volume change for converted main vocals. Measured in dB. Use -3 to"
            " decrease by 3 dB and 3 to increase by 3 dB"
        ),
    )
    parser.add_argument(
        "-bv",
        "--backup-vol",
        type=int,
        default=0,
        help="Volume change for backup vocals. Measured in dB",
    )
    parser.add_argument(
        "-iv",
        "--inst-vol",
        type=int,
        default=0,
        help="Volume change for instrumentals. Measured in dB",
    )
    parser.add_argument(
        "-osr",
        "--output-sr",
        type=int,
        default=44100,
        help="Sample rate of output audio file.",
    )
    parser.add_argument(
        "-oformat",
        "--output-format",
        type=str,
        default="mp3",
        help="format of output audio file",
    )
    parser.add_argument(
        "-k",
        "--keep-files",
        action=argparse.BooleanOptionalAction,
        default=True,
        help=(
            "Whether to keep song directory with intermediate audio files generated"
            " during song cover generation."
        ),
    )
    args = parser.parse_args()

    rvc_dirname = args.rvc_dirname

    song_cover_path = run_pipeline(
        song_input=args.song_input,
        voice_model=rvc_dirname,
        pitch_change_vocals=args.pitch_change_vocals,
        pitch_change_all=args.pitch_change_all,
        index_rate=args.index_rate,
        filter_radius=args.filter_radius,
        rms_mix_rate=args.rms_mix_rate,
        protect=args.protect,
        f0_method=args.pitch_detection_algo,
        crepe_hop_length=args.crepe_hop_length,
        reverb_rm_size=args.reverb_size,
        reverb_wet=args.reverb_wetness,
        reverb_dry=args.reverb_dryness,
        reverb_damping=args.reverb_damping,
        main_gain=args.main_vol,
        backup_gain=args.backup_vol,
        inst_gain=args.inst_vol,
        output_sr=args.output_sr,
        output_format=args.output_format,
        return_files=False,
        progress_bar=None,
    )
    print(f"[+] Cover generated at {song_cover_path}")