Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -194,9 +194,9 @@ def youtube_downloader_100s(
|
|
| 194 |
os.makedirs("output", exist_ok=True)
|
| 195 |
audio_orig = AudioSegment.from_file(audio_path)
|
| 196 |
|
| 197 |
-
if len(audio_orig) >
|
| 198 |
-
start_ms =
|
| 199 |
-
end_ms = start_ms +
|
| 200 |
|
| 201 |
# Extract the segment
|
| 202 |
|
|
@@ -213,7 +213,7 @@ def youtube_downloader_100s(
|
|
| 213 |
return f"./output/{split_model}/{filename}/vocal_{filename}.wav_10.wav", f"./output/{split_model}/{filename}/instrument_{filename}.wav_10.wav"
|
| 214 |
|
| 215 |
|
| 216 |
-
def convert(start_time, song_name_src, song_name_ref, check_song, auto_key, key_shift, vocal_vol, inst_vol):
|
| 217 |
split_model = "UVR-HP5"
|
| 218 |
song_name_ref = song_name_ref.strip().replace(" ", "")
|
| 219 |
video_identifier = search_bilibili(song_name_ref)
|
|
@@ -223,14 +223,22 @@ def convert(start_time, song_name_src, song_name_ref, check_song, auto_key, key_
|
|
| 223 |
video_identifier_src = search_bilibili(song_name_src)
|
| 224 |
song_id_src = get_bilibili_video_id(video_identifier_src)
|
| 225 |
|
| 226 |
-
if
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
-
vad("audio_ref.wav")
|
| 234 |
|
| 235 |
#if os.path.isdir(f"./output/{split_model}/{song_id_src}")==False:
|
| 236 |
audio_src, sr_src = librosa.load(youtube_downloader(video_identifier_src, song_id_src, split_model, start_time)[0], sr=24000, mono=True)
|
|
@@ -281,21 +289,22 @@ with app:
|
|
| 281 |
with gr.Row():
|
| 282 |
with gr.Column():
|
| 283 |
with gr.Row():
|
| 284 |
-
inp1 = gr.Textbox(label="请填写想要AI翻唱的歌曲或BV号", info="直接填写BV号的得到的歌曲最匹配,也可以选择填写“歌曲名+歌手名”")
|
| 285 |
-
inp2 = gr.Textbox(label="请填写含有目标音色的歌曲或BV号", info="例如您希望使用AI周杰伦的音色,就在此处填写周杰伦的任意一首歌")
|
| 286 |
with gr.Row():
|
| 287 |
inp0 = gr.Number(value=0, label="起始时间 (秒)", info="此程序将自动从起始时间开始提取45秒的翻唱歌曲")
|
| 288 |
inp3 = gr.Checkbox(label="参考音频是否为歌曲演唱,默认为是", info="如果参考音频为正常说话语音,请取消打勾", value=True)
|
| 289 |
inp4 = gr.Checkbox(label="是否自动预测歌曲人声升降调,默认为是", info="如果需要手动调节歌曲人声升降调,请取消打勾", value=True)
|
| 290 |
-
inp5 = gr.Slider(minimum=-12, maximum=12, value=0, step=1, label="歌曲人声升降调", info="默认为0,+2为升高2个key,以此类推")
|
| 291 |
with gr.Row():
|
|
|
|
| 292 |
inp6 = gr.Slider(minimum=-3, maximum=3, value=0, step=1, label="调节人声音量,默认为0")
|
| 293 |
inp7 = gr.Slider(minimum=-3, maximum=3, value=0, step=1, label="调节伴奏音量,默认为0")
|
| 294 |
btn = gr.Button("一键开启AI翻唱之旅吧💕", variant="primary")
|
| 295 |
with gr.Column():
|
| 296 |
-
|
|
|
|
| 297 |
|
| 298 |
-
btn.click(convert, [inp0, inp1, inp2, inp3, inp4, inp5, inp6, inp7], out)
|
| 299 |
|
| 300 |
gr.Markdown("### <center>注意❗:请不要生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及个人娱乐使用。</center>")
|
| 301 |
gr.HTML('''
|
|
|
|
| 194 |
os.makedirs("output", exist_ok=True)
|
| 195 |
audio_orig = AudioSegment.from_file(audio_path)
|
| 196 |
|
| 197 |
+
if len(audio_orig) > 180000:
|
| 198 |
+
start_ms = 30000
|
| 199 |
+
end_ms = start_ms + 150000
|
| 200 |
|
| 201 |
# Extract the segment
|
| 202 |
|
|
|
|
| 213 |
return f"./output/{split_model}/{filename}/vocal_{filename}.wav_10.wav", f"./output/{split_model}/{filename}/instrument_{filename}.wav_10.wav"
|
| 214 |
|
| 215 |
|
| 216 |
+
def convert(start_time, song_name_src, song_name_ref, ref_audio, check_song, auto_key, key_shift, vocal_vol, inst_vol):
|
| 217 |
split_model = "UVR-HP5"
|
| 218 |
song_name_ref = song_name_ref.strip().replace(" ", "")
|
| 219 |
video_identifier = search_bilibili(song_name_ref)
|
|
|
|
| 223 |
video_identifier_src = search_bilibili(song_name_src)
|
| 224 |
song_id_src = get_bilibili_video_id(video_identifier_src)
|
| 225 |
|
| 226 |
+
if ref_audio is None:
|
| 227 |
+
if os.path.isdir(f"./output/{split_model}/{song_id}")==False:
|
| 228 |
+
audio, sr = librosa.load(youtube_downloader_100s(video_identifier, song_id, split_model)[0], sr=24000, mono=True)
|
| 229 |
+
soundfile.write("audio_ref.wav", audio, sr)
|
| 230 |
+
else:
|
| 231 |
+
audio, sr = librosa.load(f"./output/{split_model}/{song_id}/vocal_{song_id}.wav_10.wav", sr=24000, mono=True)
|
| 232 |
+
soundfile.write("audio_ref.wav", audio, sr)
|
| 233 |
+
|
| 234 |
+
vad("audio_ref.wav")
|
| 235 |
+
else:
|
| 236 |
+
multi_channel_audio = AudioSegment.from_file(ref_audio, format="wav")
|
| 237 |
+
|
| 238 |
+
mono_audio = multi_channel_audio.set_channels(1)
|
| 239 |
+
|
| 240 |
+
mono_audio.export("voiced_audio.wav", format="wav")
|
| 241 |
|
|
|
|
| 242 |
|
| 243 |
#if os.path.isdir(f"./output/{split_model}/{song_id_src}")==False:
|
| 244 |
audio_src, sr_src = librosa.load(youtube_downloader(video_identifier_src, song_id_src, split_model, start_time)[0], sr=24000, mono=True)
|
|
|
|
| 289 |
with gr.Row():
|
| 290 |
with gr.Column():
|
| 291 |
with gr.Row():
|
| 292 |
+
inp1 = gr.Textbox(label="请填写想要AI翻唱的歌曲或BV号", placeholder="七里香 周杰伦", info="直接填写BV号的得到的歌曲最匹配,也可以选择填写“歌曲名+歌手名”")
|
| 293 |
+
inp2 = gr.Textbox(label="请填写含有目标音色的歌曲或BV号", placeholder="遇见 孙燕姿", info="例如您希望使用AI周杰伦的音色,就在此处填写周杰伦的任意一首歌")
|
| 294 |
with gr.Row():
|
| 295 |
inp0 = gr.Number(value=0, label="起始时间 (秒)", info="此程序将自动从起始时间开始提取45秒的翻唱歌曲")
|
| 296 |
inp3 = gr.Checkbox(label="参考音频是否为歌曲演唱,默认为是", info="如果参考音频为正常说话语音,请取消打勾", value=True)
|
| 297 |
inp4 = gr.Checkbox(label="是否自动预测歌曲人声升降调,默认为是", info="如果需要手动调节歌曲人声升降调,请取消打勾", value=True)
|
|
|
|
| 298 |
with gr.Row():
|
| 299 |
+
inp5 = gr.Slider(minimum=-12, maximum=12, value=0, step=1, label="歌曲人声升降调", info="默认为0,+2为升高2个key,以此类推")
|
| 300 |
inp6 = gr.Slider(minimum=-3, maximum=3, value=0, step=1, label="调节人声音量,默认为0")
|
| 301 |
inp7 = gr.Slider(minimum=-3, maximum=3, value=0, step=1, label="调节伴奏音量,默认为0")
|
| 302 |
btn = gr.Button("一键开启AI翻唱之旅吧💕", variant="primary")
|
| 303 |
with gr.Column():
|
| 304 |
+
ref_audio = gr.Audio(label="您也可以选择从本地上传一段音色参考音频", info="需要为去除伴奏后的音频,建议上传长度为60~90s左右的.wav文件;如果您希望通过歌曲名自动提取参考音频,请勿在此上传音频文件", type="filepath", interactive=True)
|
| 305 |
+
out = gr.Audio(label="AI歌手为您倾情演唱的歌曲", type="filepath", interactive=False)
|
| 306 |
|
| 307 |
+
btn.click(convert, [inp0, inp1, inp2, ref_audio, inp3, inp4, inp5, inp6, inp7], out)
|
| 308 |
|
| 309 |
gr.Markdown("### <center>注意❗:请不要生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及个人娱乐使用。</center>")
|
| 310 |
gr.HTML('''
|