mirror of
https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-06-05 01:10:22 +08:00
chore(format): run black on dev (#121)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
64f994be82
commit
3b4a546ced
27
gui.py
27
gui.py
@@ -885,12 +885,12 @@ if __name__ == "__main__":
|
||||
self.stream = AudioIoProcess(
|
||||
input_device=sd.default.device[0],
|
||||
output_device=sd.default.device[1],
|
||||
input_audio_block_size = self.block_frame,
|
||||
sample_rate = self.gui_config.samplerate,
|
||||
input_audio_block_size=self.block_frame,
|
||||
sample_rate=self.gui_config.samplerate,
|
||||
channel_num=self.gui_config.channels,
|
||||
is_input_wasapi_exclusive=wasapi_exclusive,
|
||||
is_output_wasapi_exclusive=wasapi_exclusive,
|
||||
is_device_combined = True
|
||||
is_device_combined=True,
|
||||
# TODO: Add control UI to allow devices with different type API & different WASAPI settings
|
||||
)
|
||||
self.in_mem = SharedMemory(name=self.stream.get_in_mem_name())
|
||||
@@ -899,19 +899,17 @@ if __name__ == "__main__":
|
||||
self.stream.get_np_shape(),
|
||||
dtype=self.stream.get_np_dtype(),
|
||||
buffer=self.in_mem.buf,
|
||||
order='C'
|
||||
order="C",
|
||||
)
|
||||
self.out_buf = np.ndarray(
|
||||
self.stream.get_np_shape(),
|
||||
dtype=self.stream.get_np_dtype(),
|
||||
buffer=self.out_mem.buf,
|
||||
order='C'
|
||||
order="C",
|
||||
)
|
||||
self.in_ptr, self.out_ptr, self.play_ptr, self.in_evt, self.stop_evt = (
|
||||
self.stream.get_ptrs_and_events()
|
||||
)
|
||||
self.in_ptr, \
|
||||
self.out_ptr, \
|
||||
self.play_ptr, \
|
||||
self.in_evt, \
|
||||
self.stop_evt = self.stream.get_ptrs_and_events()
|
||||
|
||||
self.stream.start()
|
||||
|
||||
@@ -919,10 +917,7 @@ if __name__ == "__main__":
|
||||
while flag_vc:
|
||||
self.audio_infer(self.block_frame << 1)
|
||||
|
||||
threading.Thread(
|
||||
target=audio_loop,
|
||||
daemon=True
|
||||
).start()
|
||||
threading.Thread(target=audio_loop, daemon=True).start()
|
||||
|
||||
def stop_stream(self):
|
||||
global flag_vc
|
||||
@@ -936,9 +931,7 @@ if __name__ == "__main__":
|
||||
self.stream.join()
|
||||
self.stream = None
|
||||
|
||||
def audio_infer(
|
||||
self, buf_size:int # 2 * self.block_frame
|
||||
):
|
||||
def audio_infer(self, buf_size: int): # 2 * self.block_frame
|
||||
"""
|
||||
音频处理
|
||||
"""
|
||||
|
||||
@@ -199,17 +199,19 @@ def get_audio_properties(input_path: str) -> Tuple[int, int]:
|
||||
container.close()
|
||||
return channels, rate
|
||||
|
||||
|
||||
class AudioIoProcess(Process):
|
||||
def __init__(self,
|
||||
input_device,
|
||||
output_device,
|
||||
input_audio_block_size: int,
|
||||
sample_rate: int,
|
||||
channel_num: int = 2,
|
||||
is_device_combined: bool = True,
|
||||
is_input_wasapi_exclusive: bool = False,
|
||||
is_output_wasapi_exclusive: bool = False
|
||||
):
|
||||
def __init__(
|
||||
self,
|
||||
input_device,
|
||||
output_device,
|
||||
input_audio_block_size: int,
|
||||
sample_rate: int,
|
||||
channel_num: int = 2,
|
||||
is_device_combined: bool = True,
|
||||
is_input_wasapi_exclusive: bool = False,
|
||||
is_output_wasapi_exclusive: bool = False,
|
||||
):
|
||||
super().__init__()
|
||||
self.in_dev = input_device
|
||||
self.out_dev = output_device
|
||||
@@ -222,18 +224,19 @@ class AudioIoProcess(Process):
|
||||
self.is_output_wasapi_exclusive: bool = is_output_wasapi_exclusive
|
||||
|
||||
self.__rec_ptr = 0
|
||||
self.in_ptr = Value('i', 0) # 当收满一个block时由本进程设置
|
||||
self.out_ptr = Value('i', 0) # 由主进程设置,指示下一次预期写入位置
|
||||
self.play_ptr = Value('i', 0) # 由本进程设置,指示当前音频已经播放到哪里
|
||||
self.in_ptr = Value("i", 0) # 当收满一个block时由本进程设置
|
||||
self.out_ptr = Value("i", 0) # 由主进程设置,指示下一次预期写入位置
|
||||
self.play_ptr = Value("i", 0) # 由本进程设置,指示当前音频已经播放到哪里
|
||||
self.in_evt = Event() # 当收满一个block时由本进程设置
|
||||
self.stop_evt = Event() # 当主进程停止音频活动时由主进程设置
|
||||
|
||||
self.latency = Value('d', 114514.1919810)
|
||||
self.latency = Value("d", 114514.1919810)
|
||||
|
||||
self.buf_shape: tuple = (self.buf_size, self.channels)
|
||||
self.buf_dtype: np.dtype = np.float32
|
||||
self.buf_nbytes: int = int(
|
||||
np.prod(self.buf_shape) * np.dtype(self.buf_dtype).itemsize)
|
||||
np.prod(self.buf_shape) * np.dtype(self.buf_dtype).itemsize
|
||||
)
|
||||
|
||||
self.in_mem = SharedMemory(create=True, size=self.buf_nbytes)
|
||||
self.out_mem = SharedMemory(create=True, size=self.buf_nbytes)
|
||||
@@ -256,11 +259,7 @@ class AudioIoProcess(Process):
|
||||
return self.buf_dtype
|
||||
|
||||
def get_ptrs_and_events(self):
|
||||
return self.in_ptr, \
|
||||
self.out_ptr,\
|
||||
self.play_ptr,\
|
||||
self.in_evt, \
|
||||
self.stop_evt\
|
||||
return self.in_ptr, self.out_ptr, self.play_ptr, self.in_evt, self.stop_evt
|
||||
|
||||
def get_latency(self) -> float:
|
||||
return self.latency.value
|
||||
@@ -272,12 +271,14 @@ class AudioIoProcess(Process):
|
||||
|
||||
in_mem = SharedMemory(name=self.in_mem_name)
|
||||
self.in_buf = np.ndarray(
|
||||
self.buf_shape, dtype=self.buf_dtype, buffer=in_mem.buf, order='C')
|
||||
self.buf_shape, dtype=self.buf_dtype, buffer=in_mem.buf, order="C"
|
||||
)
|
||||
self.in_buf.fill(0.0)
|
||||
|
||||
out_mem = SharedMemory(name=self.out_mem_name)
|
||||
self.out_buf = np.ndarray(
|
||||
self.buf_shape, dtype=self.buf_dtype, buffer=out_mem.buf, order='C')
|
||||
self.buf_shape, dtype=self.buf_dtype, buffer=out_mem.buf, order="C"
|
||||
)
|
||||
self.out_buf.fill(0.0)
|
||||
|
||||
exclusive_settings = sd.WasapiSettings(exclusive=True)
|
||||
@@ -302,11 +303,11 @@ class AudioIoProcess(Process):
|
||||
# 收录输入数据
|
||||
end_ptr = self.__rec_ptr + frames
|
||||
if end_ptr <= self.buf_size: # 整块拷贝
|
||||
self.in_buf[self.__rec_ptr:end_ptr] = indata
|
||||
self.in_buf[self.__rec_ptr : end_ptr] = indata
|
||||
else: # 处理回绕
|
||||
first = self.buf_size - self.__rec_ptr
|
||||
second = end_ptr - self.buf_size
|
||||
self.in_buf[self.__rec_ptr:] = indata[:first]
|
||||
self.in_buf[self.__rec_ptr :] = indata[:first]
|
||||
self.in_buf[:second] = indata[first:]
|
||||
write_pos = self.__rec_ptr
|
||||
self.__rec_ptr = end_ptr % self.buf_size
|
||||
@@ -328,11 +329,14 @@ class AudioIoProcess(Process):
|
||||
samplerate=self.sample_rate,
|
||||
channels=self.channels,
|
||||
dtype=self.buf_dtype,
|
||||
latency='low',
|
||||
extra_settings=exclusive_settings if
|
||||
self.is_input_wasapi_exclusive and
|
||||
self.is_output_wasapi_exclusive else None,
|
||||
callback=combined_callback
|
||||
latency="low",
|
||||
extra_settings=(
|
||||
exclusive_settings
|
||||
if self.is_input_wasapi_exclusive
|
||||
and self.is_output_wasapi_exclusive
|
||||
else None
|
||||
),
|
||||
callback=combined_callback,
|
||||
) as s:
|
||||
self.latency.value = s.latency[-1]
|
||||
self.stop_evt.wait()
|
||||
@@ -342,16 +346,20 @@ class AudioIoProcess(Process):
|
||||
samplerate=self.sample_rate,
|
||||
channels=self.channels,
|
||||
dtype=self.buf_dtype,
|
||||
latency='low',
|
||||
extra_settings=exclusive_settings if self.is_input_wasapi_exclusive else None,
|
||||
callback=input_callback
|
||||
latency="low",
|
||||
extra_settings=(
|
||||
exclusive_settings if self.is_input_wasapi_exclusive else None
|
||||
),
|
||||
callback=input_callback,
|
||||
) as si, sd.OutputStream(
|
||||
samplerate=self.sample_rate,
|
||||
channels=self.channels,
|
||||
dtype=self.buf_dtype,
|
||||
latency='low',
|
||||
extra_settings=exclusive_settings if self.is_output_wasapi_exclusive else None,
|
||||
callback=output_callback
|
||||
latency="low",
|
||||
extra_settings=(
|
||||
exclusive_settings if self.is_output_wasapi_exclusive else None
|
||||
),
|
||||
callback=output_callback,
|
||||
) as so:
|
||||
self.latency.value = si.latency[-1] + so.latency[-1]
|
||||
self.stop_evt.wait()
|
||||
|
||||
@@ -21,7 +21,7 @@ class RVC:
|
||||
self,
|
||||
key: Union[int, float],
|
||||
formant: Union[int, float],
|
||||
pth_path: FileLike, # type: ignore
|
||||
pth_path: FileLike, # type: ignore
|
||||
index_path: str,
|
||||
index_rate: Union[int, float],
|
||||
n_cpu: int = os.cpu_count(),
|
||||
|
||||
@@ -40,7 +40,7 @@ if "privateuseone" not in device:
|
||||
elif torch.backends.mps.is_available():
|
||||
device = "mps"
|
||||
else:
|
||||
import torch_directml # type: ignore
|
||||
import torch_directml # type: ignore
|
||||
|
||||
device = torch_directml.device(torch_directml.default_device())
|
||||
|
||||
@@ -88,10 +88,7 @@ def readwave(wav_path, normalize=False):
|
||||
printt("load model(s) from {}".format(model_path))
|
||||
# if hubert model is exist
|
||||
if os.access(model_path, os.F_OK) == False:
|
||||
printt(
|
||||
"Error: Extracting is shut down because %s does not exist."
|
||||
% model_path
|
||||
)
|
||||
printt("Error: Extracting is shut down because %s does not exist." % model_path)
|
||||
exit(0)
|
||||
models, saved_cfg, task = fairseq.checkpoint_utils.load_model_ensemble_and_task(
|
||||
[model_path],
|
||||
|
||||
@@ -18,7 +18,7 @@ def save_pickle(ckpt: dict, save_path: str):
|
||||
pickle.dump(ckpt, f)
|
||||
|
||||
|
||||
def load_inputs(path: FileLike, device: str, is_half=False): # type: ignore
|
||||
def load_inputs(path: FileLike, device: str, is_half=False): # type: ignore
|
||||
parm = torch.load(path, map_location=torch.device("cpu"))
|
||||
for key in parm.keys():
|
||||
parm[key] = parm[key].to(device)
|
||||
|
||||
@@ -28,9 +28,7 @@ def get_synthesizer(cpt: OrderedDict, device=torch.device("cpu")):
|
||||
return net_g, cpt
|
||||
|
||||
|
||||
def load_synthesizer(
|
||||
pth_path: FileLike, device=torch.device("cpu") # type: ignore
|
||||
):
|
||||
def load_synthesizer(pth_path: FileLike, device=torch.device("cpu")): # type: ignore
|
||||
return get_synthesizer(
|
||||
torch.load(pth_path, map_location=torch.device("cpu"), weights_only=True),
|
||||
device,
|
||||
|
||||
Reference in New Issue
Block a user