pengdaqian commited on
Commit
cfd243f
·
1 Parent(s): 85e60a5
Files changed (3) hide show
  1. app.py +31 -9
  2. music/search.py +1 -1
  3. 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
- audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
171
- if len(audio.shape) > 1:
172
- audio = librosa.to_mono(audio.transpose(1, 0))
 
 
 
 
 
 
 
 
173
  if sampling_rate != 16000:
174
- audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
175
- if len(audio) > 16000 * 100:
176
- audio = audio[:16000 * 100]
177
  wav_path = "temp.wav"
178
- soundfile.write(wav_path, audio, 16000, format="wav")
179
- out_audio = svc_change(wav_path, f"configs/singers/singer00{sid}.npy")
180
- return "Success", (48000, out_audio)
 
 
 
 
 
 
 
 
 
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="mp3")
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