Spaces:
Sleeping
Sleeping
kevinwang676
commited on
Commit
•
2c46762
1
Parent(s):
ec5a697
Update app.py
Browse files
app.py
CHANGED
@@ -213,15 +213,29 @@ 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, 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)
|
220 |
#song_id = get_bilibili_video_id(video_identifier)
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
if ref_audio is None:
|
227 |
song_name_ref = song_name_ref.strip().replace(" ", "")
|
@@ -242,8 +256,8 @@ def convert(start_time, song_name_src, song_name_ref, ref_audio, check_song, aut
|
|
242 |
|
243 |
|
244 |
#if os.path.isdir(f"./output/{split_model}/{song_id_src}")==False:
|
245 |
-
audio_src, sr_src = librosa.load(youtube_downloader(video_identifier_src, song_id_src, split_model, start_time)[0], sr=24000, mono=True)
|
246 |
-
soundfile.write("audio_src.wav", audio_src, sr_src)
|
247 |
#else:
|
248 |
# audio_src, sr_src = librosa.load(f"./output/{split_model}/{song_id_src}/vocal_{song_id_src}.wav_10.wav", sr=24000, mono=True)
|
249 |
# soundfile.write("audio_src.wav", audio_src, sr_src)
|
@@ -302,10 +316,12 @@ with app:
|
|
302 |
inp7 = gr.Slider(minimum=-3, maximum=3, value=0, step=1, label="调节伴奏音量,默认为0")
|
303 |
btn = gr.Button("一键开启AI翻唱之旅吧💕", variant="primary")
|
304 |
with gr.Column():
|
305 |
-
|
306 |
-
|
|
|
|
|
307 |
|
308 |
-
btn.click(convert, [inp0, inp1, inp2, ref_audio, inp3, inp4, inp5, inp6, inp7], out)
|
309 |
|
310 |
gr.Markdown("### <center>注意❗:请不要生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及个人娱乐使用。</center>")
|
311 |
gr.HTML('''
|
@@ -315,4 +331,5 @@ with app:
|
|
315 |
</div>
|
316 |
''')
|
317 |
|
318 |
-
app.queue(
|
|
|
|
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, src_audio, 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)
|
220 |
#song_id = get_bilibili_video_id(video_identifier)
|
221 |
+
if src_audio is None:
|
222 |
+
song_name_src = song_name_src.strip().replace(" ", "")
|
223 |
+
video_identifier_src = search_bilibili(song_name_src)
|
224 |
+
song_id_src = get_bilibili_video_id(video_identifier_src)
|
225 |
+
audio_src, sr_src = librosa.load(youtube_downloader(video_identifier_src, song_id_src, split_model, start_time)[0], sr=24000, mono=True)
|
226 |
+
soundfile.write("audio_src.wav", audio_src, sr_src)
|
227 |
+
else:
|
228 |
+
src_audio_orig = AudioSegment.from_file(src_audio)
|
229 |
+
if len(src_audio_orig) > 45000:
|
230 |
+
segment = audio_orig[0:45000]
|
231 |
+
segment.export("segment.wav", format="wav")
|
232 |
+
multi_channel_audio = AudioSegment.from_file("segment.wav", format="wav")
|
233 |
+
mono_audio = multi_channel_audio.set_channels(1)
|
234 |
+
mono_audio.export("audio_src.wav", format="wav")
|
235 |
+
else:
|
236 |
+
multi_channel_audio = AudioSegment.from_file(src_audio, format="wav")
|
237 |
+
mono_audio = multi_channel_audio.set_channels(1)
|
238 |
+
mono_audio.export("audio_src.wav", format="wav")
|
239 |
|
240 |
if ref_audio is None:
|
241 |
song_name_ref = song_name_ref.strip().replace(" ", "")
|
|
|
256 |
|
257 |
|
258 |
#if os.path.isdir(f"./output/{split_model}/{song_id_src}")==False:
|
259 |
+
#audio_src, sr_src = librosa.load(youtube_downloader(video_identifier_src, song_id_src, split_model, start_time)[0], sr=24000, mono=True)
|
260 |
+
#soundfile.write("audio_src.wav", audio_src, sr_src)
|
261 |
#else:
|
262 |
# audio_src, sr_src = librosa.load(f"./output/{split_model}/{song_id_src}/vocal_{song_id_src}.wav_10.wav", sr=24000, mono=True)
|
263 |
# soundfile.write("audio_src.wav", audio_src, sr_src)
|
|
|
316 |
inp7 = gr.Slider(minimum=-3, maximum=3, value=0, step=1, label="调节伴奏音量,默认为0")
|
317 |
btn = gr.Button("一键开启AI翻唱之旅吧💕", variant="primary")
|
318 |
with gr.Column():
|
319 |
+
with gr.Row():
|
320 |
+
src_audio = gr.Audio(label="从本地上传一段想要AI翻唱的音频。需要为去除伴奏后的音频,此程序将自动提取前45秒的音频;如果您希望通过歌曲名搜索在线音频,请勿在此上传音频文件", type="filepath", interactive=True)
|
321 |
+
ref_audio = gr.Audio(label="从本地上传一段音色参考音频。需要为去除伴奏后的音频,建议上传长度为60~90s左右的.wav文件;如果您希望通过歌曲名搜索在线音频,请勿在此上传音频文件", type="filepath", interactive=True)
|
322 |
+
out = gr.Audio(label="AI歌手为您倾情演唱的歌曲🎶", type="filepath", interactive=False)
|
323 |
|
324 |
+
btn.click(convert, [inp0, inp1, inp2, src_audio, ref_audio, inp3, inp4, inp5, inp6, inp7], out)
|
325 |
|
326 |
gr.Markdown("### <center>注意❗:请不要生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及个人娱乐使用。</center>")
|
327 |
gr.HTML('''
|
|
|
331 |
</div>
|
332 |
''')
|
333 |
|
334 |
+
app.queue(max_size=40, api_open=False)
|
335 |
+
app.launch(max_threads=400, show_error=True)
|