Skip to content

Commit

Permalink
unify code style
Browse files Browse the repository at this point in the history
  • Loading branch information
blaisewf committed Dec 21, 2024
1 parent 1ef4765 commit fe05363
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 27 deletions.
1 change: 0 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import logging

# Constants
DEFAULT_PORT = 6969
MAX_PORT_ATTEMPTS = 10

Expand Down
4 changes: 2 additions & 2 deletions rvc/configs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self):
self.gpu_mem = None
self.x_pad, self.x_query, self.x_center, self.x_max = self.device_config()

def load_config_json(self) -> dict:
def load_config_json(self):
configs = {}
for config_file in version_config_paths:
config_path = os.path.join("rvc", "configs", config_file)
Expand Down Expand Up @@ -97,7 +97,7 @@ def get_precision(self):
print(f"File not found: {full_config_path}")
return None

def device_config(self) -> tuple:
def device_config(self):
if self.device.startswith("cuda"):
self.set_cuda_config()
else:
Expand Down
3 changes: 1 addition & 2 deletions rvc/infer/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

logging.getLogger("faiss").setLevel(logging.WARNING)

# Constants for high-pass filter
FILTER_ORDER = 5
CUTOFF_FREQUENCY = 48 # Hz
SAMPLE_RATE = 16000 # Hz
Expand All @@ -43,7 +42,7 @@ def change_rms(
target_audio: np.ndarray,
target_rate: int,
rate: float,
) -> np.ndarray:
):
"""
Adjust the RMS level of target_audio to match the RMS of source_audio, with a given blending rate.
Expand Down
2 changes: 1 addition & 1 deletion rvc/lib/algorithm/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
return acts


def convert_pad_shape(pad_shape: List[List[int]]) -> List[int]:
def convert_pad_shape(pad_shape: List[List[int]]):
"""
Convert the pad shape to a list of integers.
Expand Down
6 changes: 2 additions & 4 deletions rvc/lib/algorithm/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(
self.voiced_threshold = voiced_threshold
self.waveform_dim = self.num_harmonics + 1 # fundamental + harmonics

def _compute_voiced_unvoiced(self, f0: torch.Tensor) -> torch.Tensor:
def _compute_voiced_unvoiced(self, f0: torch.Tensor):
"""
Generate a binary mask to indicate voiced/unvoiced frames.
Expand All @@ -145,9 +145,7 @@ def _compute_voiced_unvoiced(self, f0: torch.Tensor) -> torch.Tensor:
uv_mask = (f0 > self.voiced_threshold).float()
return uv_mask

def _generate_sine_wave(
self, f0: torch.Tensor, upsampling_factor: int
) -> torch.Tensor:
def _generate_sine_wave(self, f0: torch.Tensor, upsampling_factor: int):
"""
Generate sine waves for the fundamental frequency and its harmonics.
Expand Down
6 changes: 3 additions & 3 deletions rvc/lib/predictors/F0Extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def __post_init__(self):
self.x, self.sample_rate = librosa.load(self.wav_path, sr=self.sample_rate)

@property
def hop_size(self) -> float:
def hop_size(self):
return self.hop_length / self.sample_rate

@property
def wav16k(self) -> np.ndarray:
def wav16k(self):
return resampy.resample(self.x, self.sample_rate, 16000)

def extract_f0(self) -> np.ndarray:
def extract_f0(self):
f0 = None
method = self.method
if method == "crepe":
Expand Down
12 changes: 0 additions & 12 deletions rvc/lib/predictors/RMVPE.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
from librosa.filters import mel
from typing import List

# Constants for readability
N_MELS = 128
N_CLASS = 360


# Define a helper function for creating convolutional blocks
class ConvBlockRes(nn.Module):
"""
A convolutional block with residual connection.
Expand Down Expand Up @@ -59,7 +57,6 @@ def forward(self, x):
return self.conv(x) + x


# Define a class for residual encoder blocks
class ResEncoderBlock(nn.Module):
"""
A residual encoder block.
Expand Down Expand Up @@ -94,7 +91,6 @@ def forward(self, x):
return x


# Define a class for the encoder
class Encoder(nn.Module):
"""
The encoder part of the DeepUnet.
Expand Down Expand Up @@ -146,7 +142,6 @@ def forward(self, x: torch.Tensor):
return x, concat_tensors


# Define a class for the intermediate layer
class Intermediate(nn.Module):
"""
The intermediate layer of the DeepUnet.
Expand Down Expand Up @@ -177,7 +172,6 @@ def forward(self, x):
return x


# Define a class for residual decoder blocks
class ResDecoderBlock(nn.Module):
"""
A residual decoder block.
Expand Down Expand Up @@ -220,7 +214,6 @@ def forward(self, x, concat_tensor):
return x


# Define a class for the decoder
class Decoder(nn.Module):
"""
The decoder part of the DeepUnet.
Expand Down Expand Up @@ -250,7 +243,6 @@ def forward(self, x, concat_tensors):
return x


# Define a class for the DeepUnet architecture
class DeepUnet(nn.Module):
"""
The DeepUnet architecture.
Expand Down Expand Up @@ -294,7 +286,6 @@ def forward(self, x):
return x


# Define a class for the end-to-end model
class E2E(nn.Module):
"""
The end-to-end model.
Expand Down Expand Up @@ -348,7 +339,6 @@ def forward(self, mel):
return x


# Define a class for the MelSpectrogram extractor
class MelSpectrogram(torch.nn.Module):
"""
Extracts Mel-spectrogram features from audio.
Expand Down Expand Up @@ -432,7 +422,6 @@ def forward(self, audio, keyshift=0, speed=1, center=True):
return log_mel_spec


# Define a class for the RMVPE0 predictor
class RMVPE0Predictor:
"""
A predictor for fundamental frequency (F0) based on the RMVPE0 model.
Expand Down Expand Up @@ -535,7 +524,6 @@ def to_local_average_cents(self, salience, thred=0.05):
return devided


# Define a class for BiGRU (bidirectional GRU)
class BiGRU(nn.Module):
"""
A bidirectional GRU layer.
Expand Down
1 change: 0 additions & 1 deletion rvc/train/preprocess/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
logging.getLogger("numba.core.ssa").setLevel(logging.WARNING)
logging.getLogger("numba.core.interpreter").setLevel(logging.WARNING)

# Constants
OVERLAP = 0.3
MAX_AMPLITUDE = 0.9
ALPHA = 0.75
Expand Down
2 changes: 1 addition & 1 deletion tabs/extra/f0_extractor/f0_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
i18n = I18nAuto()


def extract_f0_curve(audio_path: str, method: str) -> tuple:
def extract_f0_curve(audio_path: str, method: str):
print("Extracting F0 Curve...")
image_path = os.path.join("logs", "f0_plot.png")
txt_path = os.path.join("logs", "f0_curve.txt")
Expand Down

0 comments on commit fe05363

Please sign in to comment.