From 3b4a546cede4a1ea9f70e5fbd235a0f2bb83626c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 19 Jun 2025 17:56:04 +0900 Subject: [PATCH] chore(format): run black on dev (#121) Co-authored-by: github-actions[bot] --- gui.py | 29 +++----- infer/lib/audio.py | 78 +++++++++++--------- infer/lib/rtrvc.py | 2 +- infer/modules/train/extract_feature_print.py | 7 +- rvc/jit/jit.py | 2 +- rvc/synthesizer.py | 4 +- rvc/utils/__init__.py | 2 +- 7 files changed, 60 insertions(+), 64 deletions(-) diff --git a/gui.py b/gui.py index c447de1..26bee1d 100644 --- a/gui.py +++ b/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 """ 音频处理 """ @@ -947,7 +940,7 @@ if __name__ == "__main__": self.in_evt.wait() rptr = self.in_ptr.value self.in_evt.clear() - + start_time = time.perf_counter() rend = rptr + self.block_frame diff --git a/infer/lib/audio.py b/infer/lib/audio.py index 37e76ee..8c4c092 100644 --- a/infer/lib/audio.py +++ b/infer/lib/audio.py @@ -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() diff --git a/infer/lib/rtrvc.py b/infer/lib/rtrvc.py index 1ce5e43..434839b 100644 --- a/infer/lib/rtrvc.py +++ b/infer/lib/rtrvc.py @@ -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(), diff --git a/infer/modules/train/extract_feature_print.py b/infer/modules/train/extract_feature_print.py index 09abd8a..1c3ec9a 100644 --- a/infer/modules/train/extract_feature_print.py +++ b/infer/modules/train/extract_feature_print.py @@ -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], diff --git a/rvc/jit/jit.py b/rvc/jit/jit.py index d3354dd..d66527d 100644 --- a/rvc/jit/jit.py +++ b/rvc/jit/jit.py @@ -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) diff --git a/rvc/synthesizer.py b/rvc/synthesizer.py index 6776864..f6cc688 100644 --- a/rvc/synthesizer.py +++ b/rvc/synthesizer.py @@ -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, diff --git a/rvc/utils/__init__.py b/rvc/utils/__init__.py index 75ce9c2..0df4585 100644 --- a/rvc/utils/__init__.py +++ b/rvc/utils/__init__.py @@ -1 +1 @@ -from .io import FileLike \ No newline at end of file +from .io import FileLike