Skip to content

Commit 3b4a546

Browse files
chore(format): run black on dev (#121)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 64f994b commit 3b4a546

File tree

7 files changed

+60
-64
lines changed

7 files changed

+60
-64
lines changed

gui.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -885,12 +885,12 @@ def start_stream(self):
885885
self.stream = AudioIoProcess(
886886
input_device=sd.default.device[0],
887887
output_device=sd.default.device[1],
888-
input_audio_block_size = self.block_frame,
889-
sample_rate = self.gui_config.samplerate,
888+
input_audio_block_size=self.block_frame,
889+
sample_rate=self.gui_config.samplerate,
890890
channel_num=self.gui_config.channels,
891891
is_input_wasapi_exclusive=wasapi_exclusive,
892892
is_output_wasapi_exclusive=wasapi_exclusive,
893-
is_device_combined = True
893+
is_device_combined=True,
894894
# TODO: Add control UI to allow devices with different type API & different WASAPI settings
895895
)
896896
self.in_mem = SharedMemory(name=self.stream.get_in_mem_name())
@@ -899,30 +899,25 @@ def start_stream(self):
899899
self.stream.get_np_shape(),
900900
dtype=self.stream.get_np_dtype(),
901901
buffer=self.in_mem.buf,
902-
order='C'
902+
order="C",
903903
)
904904
self.out_buf = np.ndarray(
905905
self.stream.get_np_shape(),
906906
dtype=self.stream.get_np_dtype(),
907907
buffer=self.out_mem.buf,
908-
order='C'
908+
order="C",
909+
)
910+
self.in_ptr, self.out_ptr, self.play_ptr, self.in_evt, self.stop_evt = (
911+
self.stream.get_ptrs_and_events()
909912
)
910-
self.in_ptr, \
911-
self.out_ptr, \
912-
self.play_ptr, \
913-
self.in_evt, \
914-
self.stop_evt = self.stream.get_ptrs_and_events()
915913

916914
self.stream.start()
917915

918916
def audio_loop():
919917
while flag_vc:
920918
self.audio_infer(self.block_frame << 1)
921919

922-
threading.Thread(
923-
target=audio_loop,
924-
daemon=True
925-
).start()
920+
threading.Thread(target=audio_loop, daemon=True).start()
926921

927922
def stop_stream(self):
928923
global flag_vc
@@ -936,9 +931,7 @@ def stop_stream(self):
936931
self.stream.join()
937932
self.stream = None
938933

939-
def audio_infer(
940-
self, buf_size:int # 2 * self.block_frame
941-
):
934+
def audio_infer(self, buf_size: int): # 2 * self.block_frame
942935
"""
943936
音频处理
944937
"""
@@ -947,7 +940,7 @@ def audio_infer(
947940
self.in_evt.wait()
948941
rptr = self.in_ptr.value
949942
self.in_evt.clear()
950-
943+
951944
start_time = time.perf_counter()
952945

953946
rend = rptr + self.block_frame

infer/lib/audio.py

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,19 @@ def get_audio_properties(input_path: str) -> Tuple[int, int]:
199199
container.close()
200200
return channels, rate
201201

202+
202203
class AudioIoProcess(Process):
203-
def __init__(self,
204-
input_device,
205-
output_device,
206-
input_audio_block_size: int,
207-
sample_rate: int,
208-
channel_num: int = 2,
209-
is_device_combined: bool = True,
210-
is_input_wasapi_exclusive: bool = False,
211-
is_output_wasapi_exclusive: bool = False
212-
):
204+
def __init__(
205+
self,
206+
input_device,
207+
output_device,
208+
input_audio_block_size: int,
209+
sample_rate: int,
210+
channel_num: int = 2,
211+
is_device_combined: bool = True,
212+
is_input_wasapi_exclusive: bool = False,
213+
is_output_wasapi_exclusive: bool = False,
214+
):
213215
super().__init__()
214216
self.in_dev = input_device
215217
self.out_dev = output_device
@@ -222,18 +224,19 @@ def __init__(self,
222224
self.is_output_wasapi_exclusive: bool = is_output_wasapi_exclusive
223225

224226
self.__rec_ptr = 0
225-
self.in_ptr = Value('i', 0) # 当收满一个block时由本进程设置
226-
self.out_ptr = Value('i', 0) # 由主进程设置,指示下一次预期写入位置
227-
self.play_ptr = Value('i', 0) # 由本进程设置,指示当前音频已经播放到哪里
227+
self.in_ptr = Value("i", 0) # 当收满一个block时由本进程设置
228+
self.out_ptr = Value("i", 0) # 由主进程设置,指示下一次预期写入位置
229+
self.play_ptr = Value("i", 0) # 由本进程设置,指示当前音频已经播放到哪里
228230
self.in_evt = Event() # 当收满一个block时由本进程设置
229231
self.stop_evt = Event() # 当主进程停止音频活动时由主进程设置
230232

231-
self.latency = Value('d', 114514.1919810)
233+
self.latency = Value("d", 114514.1919810)
232234

233235
self.buf_shape: tuple = (self.buf_size, self.channels)
234236
self.buf_dtype: np.dtype = np.float32
235237
self.buf_nbytes: int = int(
236-
np.prod(self.buf_shape) * np.dtype(self.buf_dtype).itemsize)
238+
np.prod(self.buf_shape) * np.dtype(self.buf_dtype).itemsize
239+
)
237240

238241
self.in_mem = SharedMemory(create=True, size=self.buf_nbytes)
239242
self.out_mem = SharedMemory(create=True, size=self.buf_nbytes)
@@ -256,11 +259,7 @@ def get_np_dtype(self) -> np.dtype:
256259
return self.buf_dtype
257260

258261
def get_ptrs_and_events(self):
259-
return self.in_ptr, \
260-
self.out_ptr,\
261-
self.play_ptr,\
262-
self.in_evt, \
263-
self.stop_evt\
262+
return self.in_ptr, self.out_ptr, self.play_ptr, self.in_evt, self.stop_evt
264263

265264
def get_latency(self) -> float:
266265
return self.latency.value
@@ -272,12 +271,14 @@ def run(self):
272271

273272
in_mem = SharedMemory(name=self.in_mem_name)
274273
self.in_buf = np.ndarray(
275-
self.buf_shape, dtype=self.buf_dtype, buffer=in_mem.buf, order='C')
274+
self.buf_shape, dtype=self.buf_dtype, buffer=in_mem.buf, order="C"
275+
)
276276
self.in_buf.fill(0.0)
277277

278278
out_mem = SharedMemory(name=self.out_mem_name)
279279
self.out_buf = np.ndarray(
280-
self.buf_shape, dtype=self.buf_dtype, buffer=out_mem.buf, order='C')
280+
self.buf_shape, dtype=self.buf_dtype, buffer=out_mem.buf, order="C"
281+
)
281282
self.out_buf.fill(0.0)
282283

283284
exclusive_settings = sd.WasapiSettings(exclusive=True)
@@ -302,11 +303,11 @@ def input_callback(indata, frames, time_info, status):
302303
# 收录输入数据
303304
end_ptr = self.__rec_ptr + frames
304305
if end_ptr <= self.buf_size: # 整块拷贝
305-
self.in_buf[self.__rec_ptr:end_ptr] = indata
306+
self.in_buf[self.__rec_ptr : end_ptr] = indata
306307
else: # 处理回绕
307308
first = self.buf_size - self.__rec_ptr
308309
second = end_ptr - self.buf_size
309-
self.in_buf[self.__rec_ptr:] = indata[:first]
310+
self.in_buf[self.__rec_ptr :] = indata[:first]
310311
self.in_buf[:second] = indata[first:]
311312
write_pos = self.__rec_ptr
312313
self.__rec_ptr = end_ptr % self.buf_size
@@ -328,11 +329,14 @@ def combined_callback(indata, outdata, frames, time_info, status):
328329
samplerate=self.sample_rate,
329330
channels=self.channels,
330331
dtype=self.buf_dtype,
331-
latency='low',
332-
extra_settings=exclusive_settings if
333-
self.is_input_wasapi_exclusive and
334-
self.is_output_wasapi_exclusive else None,
335-
callback=combined_callback
332+
latency="low",
333+
extra_settings=(
334+
exclusive_settings
335+
if self.is_input_wasapi_exclusive
336+
and self.is_output_wasapi_exclusive
337+
else None
338+
),
339+
callback=combined_callback,
336340
) as s:
337341
self.latency.value = s.latency[-1]
338342
self.stop_evt.wait()
@@ -342,16 +346,20 @@ def combined_callback(indata, outdata, frames, time_info, status):
342346
samplerate=self.sample_rate,
343347
channels=self.channels,
344348
dtype=self.buf_dtype,
345-
latency='low',
346-
extra_settings=exclusive_settings if self.is_input_wasapi_exclusive else None,
347-
callback=input_callback
349+
latency="low",
350+
extra_settings=(
351+
exclusive_settings if self.is_input_wasapi_exclusive else None
352+
),
353+
callback=input_callback,
348354
) as si, sd.OutputStream(
349355
samplerate=self.sample_rate,
350356
channels=self.channels,
351357
dtype=self.buf_dtype,
352-
latency='low',
353-
extra_settings=exclusive_settings if self.is_output_wasapi_exclusive else None,
354-
callback=output_callback
358+
latency="low",
359+
extra_settings=(
360+
exclusive_settings if self.is_output_wasapi_exclusive else None
361+
),
362+
callback=output_callback,
355363
) as so:
356364
self.latency.value = si.latency[-1] + so.latency[-1]
357365
self.stop_evt.wait()

infer/lib/rtrvc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(
2121
self,
2222
key: Union[int, float],
2323
formant: Union[int, float],
24-
pth_path: FileLike, # type: ignore
24+
pth_path: FileLike, # type: ignore
2525
index_path: str,
2626
index_rate: Union[int, float],
2727
n_cpu: int = os.cpu_count(),

infer/modules/train/extract_feature_print.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
elif torch.backends.mps.is_available():
4141
device = "mps"
4242
else:
43-
import torch_directml # type: ignore
43+
import torch_directml # type: ignore
4444

4545
device = torch_directml.device(torch_directml.default_device())
4646

@@ -88,10 +88,7 @@ def readwave(wav_path, normalize=False):
8888
printt("load model(s) from {}".format(model_path))
8989
# if hubert model is exist
9090
if os.access(model_path, os.F_OK) == False:
91-
printt(
92-
"Error: Extracting is shut down because %s does not exist."
93-
% model_path
94-
)
91+
printt("Error: Extracting is shut down because %s does not exist." % model_path)
9592
exit(0)
9693
models, saved_cfg, task = fairseq.checkpoint_utils.load_model_ensemble_and_task(
9794
[model_path],

rvc/jit/jit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def save_pickle(ckpt: dict, save_path: str):
1818
pickle.dump(ckpt, f)
1919

2020

21-
def load_inputs(path: FileLike, device: str, is_half=False): # type: ignore
21+
def load_inputs(path: FileLike, device: str, is_half=False): # type: ignore
2222
parm = torch.load(path, map_location=torch.device("cpu"))
2323
for key in parm.keys():
2424
parm[key] = parm[key].to(device)

rvc/synthesizer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ def get_synthesizer(cpt: OrderedDict, device=torch.device("cpu")):
2828
return net_g, cpt
2929

3030

31-
def load_synthesizer(
32-
pth_path: FileLike, device=torch.device("cpu") # type: ignore
33-
):
31+
def load_synthesizer(pth_path: FileLike, device=torch.device("cpu")): # type: ignore
3432
return get_synthesizer(
3533
torch.load(pth_path, map_location=torch.device("cpu"), weights_only=True),
3634
device,

rvc/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .io import FileLike
1+
from .io import FileLike

0 commit comments

Comments
 (0)