Spaces:
Runtime error
Runtime error
pengdaqian
commited on
Commit
·
cfd243f
1
Parent(s):
85e60a5
fix
Browse files- app.py +31 -9
- music/search.py +1 -1
- requirements.txt +2 -1
app.py
CHANGED
@@ -11,6 +11,9 @@ import numpy as np
|
|
11 |
import soundfile
|
12 |
import random
|
13 |
from audio2numpy import open_audio
|
|
|
|
|
|
|
14 |
|
15 |
import logging
|
16 |
|
@@ -78,6 +81,8 @@ model = SynthesizerInfer(
|
|
78 |
load_svc_model("vits_pretrain/sovits5.0-48k-debug.pth", model)
|
79 |
model.eval()
|
80 |
model.to(device)
|
|
|
|
|
81 |
|
82 |
|
83 |
def svc_change(argswave, argsspk):
|
@@ -167,17 +172,34 @@ def svc_main(sid, input_audio):
|
|
167 |
if input_audio is None:
|
168 |
return "You need to upload an audio", None
|
169 |
sampling_rate, audio = input_audio
|
170 |
-
|
171 |
-
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
if sampling_rate != 16000:
|
174 |
-
|
175 |
-
if len(
|
176 |
-
|
177 |
wav_path = "temp.wav"
|
178 |
-
soundfile.write(wav_path,
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
|
183 |
def auto_search(name):
|
|
|
11 |
import soundfile
|
12 |
import random
|
13 |
from audio2numpy import open_audio
|
14 |
+
from spleeter.separator import Separator
|
15 |
+
from spleeter.audio.adapter import AudioAdapter
|
16 |
+
from pydub import AudioSegment
|
17 |
|
18 |
import logging
|
19 |
|
|
|
81 |
load_svc_model("vits_pretrain/sovits5.0-48k-debug.pth", model)
|
82 |
model.eval()
|
83 |
model.to(device)
|
84 |
+
separator = Separator('spleeter:2stems')
|
85 |
+
audio_loader = AudioAdapter.default()
|
86 |
|
87 |
|
88 |
def svc_change(argswave, argsspk):
|
|
|
172 |
if input_audio is None:
|
173 |
return "You need to upload an audio", None
|
174 |
sampling_rate, audio = input_audio
|
175 |
+
#
|
176 |
+
prediction = separator.separate(audio)
|
177 |
+
vocals, accompaniment = prediction["vocals"], prediction["accompaniment"]
|
178 |
+
|
179 |
+
# 歌词和伴奏是否有问题
|
180 |
+
audio_loader.save('vocals_111.wav', vocals, sampling_rate)
|
181 |
+
audio_loader.save('accompaniment_111.wav', accompaniment, sampling_rate)
|
182 |
+
|
183 |
+
vocals = (vocals / np.iinfo(vocals.dtype).max).astype(np.float32)
|
184 |
+
if len(vocals.shape) > 1:
|
185 |
+
vocals = librosa.to_mono(vocals.transpose(1, 0))
|
186 |
if sampling_rate != 16000:
|
187 |
+
vocals = librosa.resample(vocals, orig_sr=sampling_rate, target_sr=16000)
|
188 |
+
if len(vocals) > 16000 * 100:
|
189 |
+
vocals = vocals[:16000 * 100]
|
190 |
wav_path = "temp.wav"
|
191 |
+
soundfile.write(wav_path, vocals, 16000, format="wav")
|
192 |
+
|
193 |
+
out_vocals = svc_change(wav_path, f"configs/singers/singer00{sid}.npy")
|
194 |
+
|
195 |
+
audio_loader.save('out_vocals_111.wav', out_vocals, 48000)
|
196 |
+
|
197 |
+
sound1 = AudioSegment.from_file("out_vocals_111.wav")
|
198 |
+
sound2 = AudioSegment.from_file("accompaniment_111.wav")
|
199 |
+
|
200 |
+
played_togther = sound1.overlay(sound2)
|
201 |
+
|
202 |
+
return "Success", (48000, played_togther)
|
203 |
|
204 |
|
205 |
def auto_search(name):
|
music/search.py
CHANGED
@@ -87,5 +87,5 @@ def get_random_spit(songinfo):
|
|
87 |
if right_idx > length:
|
88 |
right_idx = length
|
89 |
middle_30s = song[left_idx:right_idx]
|
90 |
-
middle_30s.export(save_path, format="
|
91 |
return save_path
|
|
|
87 |
if right_idx > length:
|
88 |
right_idx = length
|
89 |
middle_30s = song[left_idx:right_idx]
|
90 |
+
middle_30s.export(save_path, format="wav")
|
91 |
return save_path
|
requirements.txt
CHANGED
@@ -14,4 +14,5 @@ tqdm
|
|
14 |
librosa
|
15 |
pydub
|
16 |
musicdl
|
17 |
-
audio2numpy
|
|
|
|
14 |
librosa
|
15 |
pydub
|
16 |
musicdl
|
17 |
+
audio2numpy
|
18 |
+
spleeter
|