Skip to content

Commit c353151

Browse files
committed
chore: run autoflake and black formatting
1 parent 5ef0a37 commit c353151

8 files changed

Lines changed: 73 additions & 41 deletions

File tree

app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@
2727
# connection during asyncio shutdown (WinError 10054 / ProactorBasePipeTransport).
2828
if sys.platform == "win32":
2929
import asyncio.proactor_events as _pe
30+
3031
_orig_ccl = _pe._ProactorBasePipeTransport._call_connection_lost
32+
3133
def _ccl_patched(self, exc):
3234
try:
3335
_orig_ccl(self, exc)
3436
except ConnectionResetError:
3537
pass
38+
3639
_pe._ProactorBasePipeTransport._call_connection_lost = _ccl_patched
3740

3841
# Zluda hijack

rvc/realtime/audio.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,7 @@ def start(
390390
if asio_output_stereo
391391
else [asio_output_channel]
392392
)
393-
output_extra_setting = sd.AsioSettings(
394-
channel_selectors=output_selectors
395-
)
393+
output_extra_setting = sd.AsioSettings(channel_selectors=output_selectors)
396394
output_channels = len(output_selectors)
397395

398396
if self.use_monitor:
@@ -414,7 +412,9 @@ def start(
414412
)
415413
monitor_channels = 1
416414

417-
block_frame = int((read_chunk_size * 128 / AUDIO_SAMPLE_RATE) * audio_sample_rate)
415+
block_frame = int(
416+
(read_chunk_size * 128 / AUDIO_SAMPLE_RATE) * audio_sample_rate
417+
)
418418

419419
try:
420420
self.run_audio_stream(

rvc/realtime/callbacks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ def change_voice(
130130
return audio, vol, [0, perf_ms, 0], None
131131

132132
# No result ready yet; replay previous output to avoid underrun.
133-
if self._last_output is not None and self._last_output.shape[0] == received_data.shape[0]:
133+
if (
134+
self._last_output is not None
135+
and self._last_output.shape[0] == received_data.shape[0]
136+
):
134137
return self._last_output, self._last_vol, [0, 0, 0], None
135138

136139
return np.zeros(received_data.shape[0], dtype=np.float32), 0, [0, 0, 0], None

rvc/realtime/core.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,7 @@ def inference(
366366
)
367367

368368
# Scale output by the current input RMS to suppress residue during silence.
369-
audio_out: torch.Tensor = self.resample_out(
370-
audio_model * vol_t
371-
)
369+
audio_out: torch.Tensor = self.resample_out(audio_model * vol_t)
372370
return audio_out, vol, False
373371

374372
def __del__(self):
@@ -531,11 +529,7 @@ def process_audio(
531529
n_hops = block_size // hop
532530
if n_hops >= 1:
533531
hop_energy = (
534-
audio[: n_hops * hop]
535-
.reshape(n_hops, hop)
536-
.abs()
537-
.max(dim=1)
538-
.values
532+
audio[: n_hops * hop].reshape(n_hops, hop).abs().max(dim=1).values
539533
)
540534
peak = hop_energy.max().item()
541535
onset_sample = 0
@@ -562,7 +556,9 @@ def process_audio(
562556
# Pad if audio is shorter than block_size + crossfade_frame.
563557
_need = block_size + self.crossfade_frame
564558
if audio.shape[0] < _need:
565-
pad = torch.zeros(_need - audio.shape[0], device=audio.device, dtype=audio.dtype)
559+
pad = torch.zeros(
560+
_need - audio.shape[0], device=audio.device, dtype=audio.dtype
561+
)
566562
audio = torch.cat([audio, pad])
567563
self.sola_buffer[:] = audio[block_size : block_size + self.crossfade_frame]
568564
audio_output = audio[:block_size].detach().cpu().numpy()

rvc/realtime/pipeline.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,11 @@ def voice_conversion(
255255
if self.use_f0:
256256
# Extract F0 from the most recent audio window only.
257257
shift = (block_size_16k or skip_head * self.window) // self.window
258-
f0_frame = block_size_16k + 800 if block_size_16k else skip_head * self.window + 800
258+
f0_frame = (
259+
block_size_16k + 800
260+
if block_size_16k
261+
else skip_head * self.window + 800
262+
)
259263
if self.f0_method == "rmvpe":
260264
f0_frame = 5120 * ((f0_frame - 1) // 5120 + 1) - 160
261265
f0_frame = min(f0_frame, audio.shape[0])
@@ -272,15 +276,17 @@ def voice_conversion(
272276
)
273277
# Remove batch dimension.
274278
f0_coarse_new = f0_coarse_new.squeeze(0)
275-
f0_new = f0_new.squeeze(0)
279+
f0_new = f0_new.squeeze(0)
276280

277281
# Shift pitch cache left by one block and append new frames (trimmed [3:-1]).
278282
pitch[:-shift] = pitch[shift:].clone()
279283
pitchf[:-shift] = pitchf[shift:].clone()
280-
interior_coarse = f0_coarse_new[3:-1] if f0_coarse_new.shape[0] > 4 else f0_coarse_new
281-
interior_f = f0_new[3:-1] if f0_new.shape[0] > 4 else f0_new
282-
pitch[-interior_coarse.shape[0]:] = interior_coarse
283-
pitchf[-interior_f.shape[0]:] = interior_f
284+
interior_coarse = (
285+
f0_coarse_new[3:-1] if f0_coarse_new.shape[0] > 4 else f0_coarse_new
286+
)
287+
interior_f = f0_new[3:-1] if f0_new.shape[0] > 4 else f0_new
288+
pitch[-interior_coarse.shape[0] :] = interior_coarse
289+
pitchf[-interior_f.shape[0] :] = interior_f
284290
else:
285291
pitch, pitchf = None, None
286292

@@ -316,8 +322,10 @@ def voice_conversion(
316322
feats0 = F.interpolate(feats0.permute(0, 2, 1), scale_factor=2).permute(
317323
0, 2, 1
318324
)[:, :p_len, :]
319-
pitch_p = pitch[-p_len:].unsqueeze(0)
320-
pitchf_p = pitchf[-p_len:].unsqueeze(0) * (formant_length / return_length)
325+
pitch_p = pitch[-p_len:].unsqueeze(0)
326+
pitchf_p = pitchf[-p_len:].unsqueeze(0) * (
327+
formant_length / return_length
328+
)
321329

322330
# Pitch protection blending
323331
if protect < 0.5:
@@ -342,7 +350,7 @@ def voice_conversion(
342350
).float()
343351
# Match output RMS to the current block's input RMS.
344352
if volume_envelope < 1:
345-
rms_src = audio[-(return_length * self.window):].cpu().numpy()
353+
rms_src = audio[-(return_length * self.window) :].cpu().numpy()
346354
out_audio = AudioProcessor.change_rms(
347355
rms_src,
348356
self.sample_rate,

rvc/realtime/worker.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ def _apply_config(vc, cfg):
7474
vc.crossfade_frame = cf
7575
vc.extra_frame = ef
7676
vc.vc_model.realloc(
77-
vc.block_frame, vc.extra_frame,
78-
vc.crossfade_frame, vc.sola_search_frame,
77+
vc.block_frame,
78+
vc.extra_frame,
79+
vc.crossfade_frame,
80+
vc.sola_search_frame,
7981
)
8082
vc.generate_strength()
8183

@@ -89,6 +91,7 @@ def _apply_config(vc, cfg):
8991
vc.vc_model.vad = None
9092
elif vc.vc_model.vad is None:
9193
from rvc.realtime.utils.vad import VADProcessor
94+
9295
vc.vc_model.vad = VADProcessor(
9396
sensitivity_mode=cfg.get("vad_sensitivity", 3),
9497
sample_rate=vc.vc_model.sample_rate,
@@ -103,6 +106,7 @@ def _apply_config(vc, cfg):
103106
strength = cfg.get("clean_strength", 0.5)
104107
if vc.vc_model.reduced_noise is None:
105108
from noisereduce.torchgate import TorchGate
109+
106110
vc.vc_model.reduced_noise = TorchGate(
107111
vc.vc_model.pipeline.tgt_sr,
108112
prop_decrease=strength,
@@ -124,6 +128,7 @@ def _apply_config(vc, cfg):
124128
if model_path and vc.vc_model.model_path != model_path:
125129
import torch
126130
import torchaudio.transforms as tat
131+
127132
vc.vc_model.model_path = model_path
128133
vc.vc_model.pipeline.vc.load_model(model_path)
129134
vc.vc_model.pipeline.vc.setup_network()
@@ -138,6 +143,7 @@ def _apply_config(vc, cfg):
138143
sid = cfg.get("sid")
139144
if sid is not None and vc.vc_model.pipeline.sid != sid:
140145
import torch
146+
141147
vc.vc_model.pipeline.torch_sid = torch.tensor(
142148
[sid], device=vc.vc_model.pipeline.device, dtype=torch.int64
143149
)
@@ -147,9 +153,14 @@ def _apply_config(vc, cfg):
147153
if index_path is not None:
148154
if index_path and vc.vc_model.index_path != index_path:
149155
from rvc.realtime.pipeline import load_faiss_index
156+
150157
index, big_npy = load_faiss_index(
151-
index_path.strip().strip('"').strip("\n").strip('"')
152-
.strip().replace("trained", "added")
158+
index_path.strip()
159+
.strip('"')
160+
.strip("\n")
161+
.strip('"')
162+
.strip()
163+
.replace("trained", "added")
153164
)
154165
vc.vc_model.pipeline.index = index
155166
vc.vc_model.pipeline.big_npy = big_npy
@@ -174,6 +185,7 @@ def _apply_config(vc, cfg):
174185
or vc.vc_model.embedder_model_custom != emb_custom
175186
):
176187
from rvc.lib.utils import load_embedding
188+
177189
old = vc.vc_model.pipeline.hubert_model
178190
del old
179191
hubert_model = load_embedding(emb, emb_custom)

tabs/realtime/realtime.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,13 @@ def refresh_embedders_folders():
284284

285285

286286
def save_realtime_settings(
287-
input_device, output_device, monitor_device, model_file, index_file,
288-
asio_enabled=None, audio_sample_rate=None,
287+
input_device,
288+
output_device,
289+
monitor_device,
290+
model_file,
291+
index_file,
292+
asio_enabled=None,
293+
audio_sample_rate=None,
289294
):
290295
"""Save realtime settings to config.json"""
291296
try:
@@ -349,7 +354,9 @@ def load_realtime_settings():
349354
"model_file": realtime_config.get("model_file", ""),
350355
"index_file": realtime_config.get("index_file", ""),
351356
"asio_enabled": realtime_config.get("asio_enabled", False),
352-
"audio_sample_rate": realtime_config.get("audio_sample_rate", 48000),
357+
"audio_sample_rate": realtime_config.get(
358+
"audio_sample_rate", 48000
359+
),
353360
}
354361
except Exception as e:
355362
print(f"Error loading realtime settings: {e}")
@@ -532,7 +539,9 @@ def start_realtime(
532539
_rt_cfg = load_realtime_settings()
533540
asio_enabled = _rt_cfg["asio_enabled"]
534541
audio_sample_rate = _rt_cfg["audio_sample_rate"]
535-
audio_sample_rate = resolve_sample_rate(input_device_id, asio_enabled, audio_sample_rate)
542+
audio_sample_rate = resolve_sample_rate(
543+
input_device_id, asio_enabled, audio_sample_rate
544+
)
536545
read_chunk_size = int(chunk_size * audio_sample_rate / 1000 / 128)
537546

538547
callbacks_kwargs = {
@@ -643,7 +652,9 @@ def start_realtime(
643652
else 0
644653
)
645654
if warmup_remaining > 0:
646-
yield i18n("Warming up... ({} blocks remaining)").format(warmup_remaining), interactive_false, interactive_true
655+
yield i18n("Warming up... ({} blocks remaining)").format(
656+
warmup_remaining
657+
), interactive_false, interactive_true
647658
else:
648659
yield f"Latency: {audio_manager.latency:.2f} ms | Volume: {audio_manager.volume:.2f} dB", interactive_false, interactive_true
649660

@@ -845,11 +856,13 @@ def soundfile_record_audio(
845856
now_dir, "assets", "audios", "record_audio.wav"
846857
)
847858

848-
callbacks.vc.send_config({
849-
"record_start": True,
850-
"record_audio_path": record_audio_path,
851-
"export_format": export_format,
852-
})
859+
callbacks.vc.send_config(
860+
{
861+
"record_start": True,
862+
"record_audio_path": record_audio_path,
863+
"export_format": export_format,
864+
}
865+
)
853866

854867
return "Stop", None
855868
else:
@@ -1080,7 +1093,6 @@ def realtime_tab():
10801093
interactive=True,
10811094
)
10821095

1083-
10841096
with gr.TabItem(i18n("Model Settings")):
10851097
with gr.Row():
10861098
model_choices = (

tabs/settings/sections/realtime_audio.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ def realtime_audio_tab():
6262
with gr.Column():
6363
asio_enabled = gr.Checkbox(
6464
label=i18n("Enable ASIO"),
65-
info=i18n(
66-
"Enable ASIO driver support. (Requires restarting Applio)"
67-
),
65+
info=i18n("Enable ASIO driver support. (Requires restarting Applio)"),
6866
value=saved_asio,
6967
interactive=True,
7068
visible=IS_WINDOWS,

0 commit comments

Comments
 (0)