Skip to content

Commit

Permalink
chore(format): run black on dev (#101)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and github-actions[bot] authored Nov 28, 2024
1 parent 5969314 commit 51c85fc
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 20 deletions.
3 changes: 1 addition & 2 deletions infer/lib/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def frame_iter(container):

np.copyto(decoded_audio[..., offset:end_index], frame_data)
offset += len(frame_data[0])

container.close()

# Truncate the array to the actual size
Expand Down Expand Up @@ -188,7 +188,6 @@ def resample_audio(
output_container.close()



def get_audio_properties(input_path: str) -> Tuple[int, int]:
container = av.open(input_path)
audio_stream = next(s for s in container.streams if s.type == "audio")
Expand Down
8 changes: 7 additions & 1 deletion infer/lib/train/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ def summarize(

def latest_checkpoint_path(dir_path, regex="G_*.pth"):
f_list = glob.glob(os.path.join(dir_path, regex))
f_list.sort(key=lambda f: 999999999999 if isinstance(f, str) and f == "latest" else int("0"+"".join(filter(str.isdigit, f))))
f_list.sort(
key=lambda f: (
999999999999
if isinstance(f, str) and f == "latest"
else int("0" + "".join(filter(str.isdigit, f)))
)
)
x = f_list[-1]
logger.debug(x)
return x
Expand Down
25 changes: 16 additions & 9 deletions infer/lib/uvr5_pack/lib_v5/spec_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def crop_center(h1, h2):
return h1


def split_lr_waves(
wave, mid_side=False, mid_side_b2=False, reverse=False
):
def split_lr_waves(wave, mid_side=False, mid_side_b2=False, reverse=False):
if reverse:
wave_left = np.flip(np.asfortranarray(wave[0]))
wave_right = np.flip(np.asfortranarray(wave[1]))
Expand All @@ -48,17 +46,23 @@ def run_librosa_stft(wv, n_fft, hop_length, reverse):
return librosa.stft(wv, n_fft=n_fft, hop_length=hop_length)
return librosa.stft(np.asfortranarray(wv), n_fft=n_fft, hop_length=hop_length)


def wave_to_spectrogram_mt(
wave, hop_length, n_fft, mid_side=False, mid_side_b2=False, reverse=False
):

with ThreadPoolExecutor(max_workers=2) as tp:
spec = np.asfortranarray(
[spec for spec in tp.map(
run_librosa_stft,
split_lr_waves(wave, mid_side, mid_side_b2, reverse),
[n_fft, n_fft], [hop_length, hop_length], [reverse, reverse]
)]
[
spec
for spec in tp.map(
run_librosa_stft,
split_lr_waves(wave, mid_side, mid_side_b2, reverse),
[n_fft, n_fft],
[hop_length, hop_length],
[reverse, reverse],
)
]
)

return spec
Expand Down Expand Up @@ -144,10 +148,13 @@ def mask_silence(mag, ref, thres=0.2, min_range=64, fade_size=32):
def run_librosa_istft(specx, hop_length):
return librosa.istft(np.asfortranarray(specx), hop_length=hop_length)


def spectrogram_to_wave(spec, hop_length, mid_side, mid_side_b2, reverse):

with ThreadPoolExecutor(max_workers=2) as tp:
wave_left, wave_right = tp.map(run_librosa_istft, spec, [hop_length, hop_length])
wave_left, wave_right = tp.map(
run_librosa_istft, spec, [hop_length, hop_length]
)

if reverse:
return np.asfortranarray([np.flip(wave_left), np.flip(wave_right)])
Expand Down
13 changes: 11 additions & 2 deletions infer/modules/uvr5/mdxnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,21 @@ def prediction(self, m, vocal_root, others_root, format):
sources = self.demix(mix.T)
opt = sources[0].T
save_audio(
"%s/vocal_%s.%s" % (vocal_root, basename, format), mix - opt, rate, True, format=format,
"%s/vocal_%s.%s" % (vocal_root, basename, format),
mix - opt,
rate,
True,
format=format,
)
save_audio(
"%s/instrument_%s.%s" % (others_root, basename, format), opt, rate, True, format=format,
"%s/instrument_%s.%s" % (others_root, basename, format),
opt,
rate,
True,
format=format,
)


class MDXNetDereverb:
def __init__(self, chunks, device):
self.onnx = "assets/uvr5_weights/onnx_dereverb_By_FoxJoy"
Expand Down
14 changes: 10 additions & 4 deletions infer/modules/uvr5/vr.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def _path_audio_(self, music_file, ins_root=None, vocal_root=None, format="flac"
if ins_root is not None:
if self.data["high_end_process"].startswith("mirroring"):
input_high_end_ = spec_utils.mirroring(
self.data["high_end_process"], y_spec_m, input_high_end, self.mp.param["pre_filter_start"]
self.data["high_end_process"],
y_spec_m,
input_high_end,
self.mp.param["pre_filter_start"],
)
wav_instrument = spec_utils.cmb_spectrogram_to_wave(
y_spec_m, self.mp, input_high_end_h, input_high_end_
Expand All @@ -139,7 +142,7 @@ def _path_audio_(self, music_file, ins_root=None, vocal_root=None, format="flac"
wav_instrument,
self.mp.param["sr"],
f32=True,
format=format
format=format,
)
if vocal_root is not None:
if self.is_reverse:
Expand All @@ -148,7 +151,10 @@ def _path_audio_(self, music_file, ins_root=None, vocal_root=None, format="flac"
head = "vocal_"
if self.data["high_end_process"].startswith("mirroring"):
input_high_end_ = spec_utils.mirroring(
self.data["high_end_process"], v_spec_m, input_high_end, self.mp.param["pre_filter_start"]
self.data["high_end_process"],
v_spec_m,
input_high_end,
self.mp.param["pre_filter_start"],
)
wav_vocals = spec_utils.cmb_spectrogram_to_wave(
v_spec_m, self.mp, input_high_end_h, input_high_end_
Expand All @@ -164,5 +170,5 @@ def _path_audio_(self, music_file, ins_root=None, vocal_root=None, format="flac"
wav_vocals,
self.mp.param["sr"],
f32=True,
format=format
format=format,
)
3 changes: 1 addition & 2 deletions infer/modules/vc/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ def vc_multi(
try:
tgt_sr, audio_opt = opt
save_audio(
"%s/%s.%s"
% (opt_root, os.path.basename(path), format1),
"%s/%s.%s" % (opt_root, os.path.basename(path), format1),
audio_opt,
tgt_sr,
f32=True,
Expand Down

0 comments on commit 51c85fc

Please sign in to comment.