mirror of
https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-06-07 19:40:44 +08:00
chore(format): run black on dev
This commit is contained in:
@@ -41,10 +41,12 @@ def load_audio(file: str, sr: int) -> np.ndarray:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
container = av.open(file)
|
container = av.open(file)
|
||||||
resampler = AudioResampler(format='fltp', layout='mono', rate=sr)
|
resampler = AudioResampler(format="fltp", layout="mono", rate=sr)
|
||||||
|
|
||||||
# AV stores duration in nanoseconds
|
# AV stores duration in nanoseconds
|
||||||
decoded_audio = (((container.duration * sr / container.bit_rate) // 1_000_000) + 1)*[]
|
decoded_audio = (
|
||||||
|
((container.duration * sr / container.bit_rate) // 1_000_000) + 1
|
||||||
|
) * []
|
||||||
|
|
||||||
for frame in container.decode(audio=0):
|
for frame in container.decode(audio=0):
|
||||||
frame.pts = None # Clear presentation timestamp to avoid resampling issues
|
frame.pts = None # Clear presentation timestamp to avoid resampling issues
|
||||||
@@ -57,17 +59,19 @@ def load_audio(file: str, sr: int) -> np.ndarray:
|
|||||||
|
|
||||||
return np.frombuffer(audio, dtype=np.float32).flatten()
|
return np.frombuffer(audio, dtype=np.float32).flatten()
|
||||||
|
|
||||||
|
|
||||||
def downsample_audio(input_path: str, output_path: str, format: str) -> None:
|
def downsample_audio(input_path: str, output_path: str, format: str) -> None:
|
||||||
if not os.path.exists(input_path): return
|
if not os.path.exists(input_path):
|
||||||
|
return
|
||||||
|
|
||||||
input_container = av.open(input_path)
|
input_container = av.open(input_path)
|
||||||
output_container = av.open(output_path, 'w')
|
output_container = av.open(output_path, "w")
|
||||||
|
|
||||||
# Create a stream in the output container
|
# Create a stream in the output container
|
||||||
input_stream = input_container.streams.audio[0]
|
input_stream = input_container.streams.audio[0]
|
||||||
output_stream = output_container.add_stream(format)
|
output_stream = output_container.add_stream(format)
|
||||||
|
|
||||||
output_stream.bit_rate = 128_000 # 128kb/s (equivalent to -q:a 2)
|
output_stream.bit_rate = 128_000 # 128kb/s (equivalent to -q:a 2)
|
||||||
|
|
||||||
# Copy packets from the input file to the output file
|
# Copy packets from the input file to the output file
|
||||||
for packet in input_container.demux(input_stream):
|
for packet in input_container.demux(input_stream):
|
||||||
@@ -82,16 +86,20 @@ def downsample_audio(input_path: str, output_path: str, format: str) -> None:
|
|||||||
input_container.close()
|
input_container.close()
|
||||||
output_container.close()
|
output_container.close()
|
||||||
|
|
||||||
try: # Remove the original file
|
try: # Remove the original file
|
||||||
os.remove(input_path)
|
os.remove(input_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to remove the original file: {e}")
|
print(f"Failed to remove the original file: {e}")
|
||||||
|
|
||||||
def resample_audio(input_path: str, output_path: str, codec: str, format: str, sr: int, layout: str) -> None:
|
|
||||||
if not os.path.exists(input_path): return
|
def resample_audio(
|
||||||
|
input_path: str, output_path: str, codec: str, format: str, sr: int, layout: str
|
||||||
|
) -> None:
|
||||||
|
if not os.path.exists(input_path):
|
||||||
|
return
|
||||||
|
|
||||||
input_container = av.open(input_path)
|
input_container = av.open(input_path)
|
||||||
output_container = av.open(output_path, 'w')
|
output_container = av.open(output_path, "w")
|
||||||
|
|
||||||
# Create a stream in the output container
|
# Create a stream in the output container
|
||||||
input_stream = input_container.streams.audio[0]
|
input_stream = input_container.streams.audio[0]
|
||||||
@@ -115,18 +123,20 @@ def resample_audio(input_path: str, output_path: str, codec: str, format: str, s
|
|||||||
input_container.close()
|
input_container.close()
|
||||||
output_container.close()
|
output_container.close()
|
||||||
|
|
||||||
try: # Remove the original file
|
try: # Remove the original file
|
||||||
os.remove(input_path)
|
os.remove(input_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to remove the original file: {e}")
|
print(f"Failed to remove the original file: {e}")
|
||||||
|
|
||||||
|
|
||||||
def get_audio_properties(input_path: str) -> Tuple:
|
def get_audio_properties(input_path: str) -> Tuple:
|
||||||
container = av.open(input_path)
|
container = av.open(input_path)
|
||||||
audio_stream = next(s for s in container.streams if s.type == 'audio')
|
audio_stream = next(s for s in container.streams if s.type == "audio")
|
||||||
channels = 1 if audio_stream.layout == 'mono' else 2
|
channels = 1 if audio_stream.layout == "mono" else 2
|
||||||
rate = audio_stream.base_rate
|
rate = audio_stream.base_rate
|
||||||
container.close()
|
container.close()
|
||||||
return channels, rate
|
return channels, rate
|
||||||
|
|
||||||
|
|
||||||
def clean_path(path: str) -> Path:
|
def clean_path(path: str) -> Path:
|
||||||
return Path(path.strip(' "\n')).resolve()
|
return Path(path.strip(' "\n')).resolve()
|
||||||
|
|||||||
@@ -224,6 +224,7 @@ class Predictor:
|
|||||||
downsample_audio(path_vocal, opt_path_vocal, format)
|
downsample_audio(path_vocal, opt_path_vocal, format)
|
||||||
downsample_audio(path_other, opt_path_other, format)
|
downsample_audio(path_other, opt_path_other, format)
|
||||||
|
|
||||||
|
|
||||||
class MDXNetDereverb:
|
class MDXNetDereverb:
|
||||||
def __init__(self, chunks, device):
|
def __init__(self, chunks, device):
|
||||||
self.onnx = "assets/uvr5_weights/onnx_dereverb_By_FoxJoy"
|
self.onnx = "assets/uvr5_weights/onnx_dereverb_By_FoxJoy"
|
||||||
|
|||||||
@@ -50,7 +50,9 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format
|
|||||||
|
|
||||||
# Check the audio stream's properties
|
# Check the audio stream's properties
|
||||||
if channels == 2 and rate == 44100:
|
if channels == 2 and rate == 44100:
|
||||||
pre_fun._path_audio_(inp_path, save_root_ins, save_root_vocal, format0, is_hp3=is_hp3)
|
pre_fun._path_audio_(
|
||||||
|
inp_path, save_root_ins, save_root_vocal, format0, is_hp3=is_hp3
|
||||||
|
)
|
||||||
need_reformat = 0
|
need_reformat = 0
|
||||||
done = 1
|
done = 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -61,7 +63,7 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format
|
|||||||
os.path.join(os.environ["TEMP"]),
|
os.path.join(os.environ["TEMP"]),
|
||||||
os.path.basename(inp_path),
|
os.path.basename(inp_path),
|
||||||
)
|
)
|
||||||
resample_audio(inp_path, tmp_path, 'pcm_s16le', 's16', 44100, 'stereo')
|
resample_audio(inp_path, tmp_path, "pcm_s16le", "s16", 44100, "stereo")
|
||||||
inp_path = tmp_path
|
inp_path = tmp_path
|
||||||
try:
|
try:
|
||||||
if done == 0:
|
if done == 0:
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ class AudioPre:
|
|||||||
opt_format_path = path[:-4] + ".%s" % format
|
opt_format_path = path[:-4] + ".%s" % format
|
||||||
downsample_audio(path, opt_format_path, format)
|
downsample_audio(path, opt_format_path, format)
|
||||||
|
|
||||||
|
|
||||||
class AudioPreDeEcho:
|
class AudioPreDeEcho:
|
||||||
def __init__(self, agg, model_path, device, is_half, tta=False):
|
def __init__(self, agg, model_path, device, is_half, tta=False):
|
||||||
self.model_path = model_path
|
self.model_path = model_path
|
||||||
|
|||||||
Reference in New Issue
Block a user