-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery Starbot ⭐ refactored ikrom96git/Real-Time-Voice-Cloning #1
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
print("Caught exception: %s" % repr(e)) | ||
print(f"Caught exception: {repr(e)}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 207-207
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
@@ -5,6 +5,7 @@ | |||
|
|||
|
|||
if __name__ == "__main__": | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 70-70
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
if isinstance(fpath_or_wav, str) or isinstance(fpath_or_wav, Path): | ||
if isinstance(fpath_or_wav, (str, Path)): | ||
wav, source_sr = librosa.load(str(fpath_or_wav), sr=None) | ||
else: | ||
wav = fpath_or_wav | ||
|
||
# Resample the wav if needed | ||
if source_sr is not None and source_sr != sampling_rate: | ||
wav = librosa.resample(wav, source_sr, sampling_rate) | ||
|
||
# Apply the preprocessing: normalize volume and shorten long silences | ||
if normalize: | ||
wav = normalize_volume(wav, audio_norm_target_dBFS, increase_only=True) | ||
if webrtcvad and trim_silence: | ||
wav = trim_long_silences(wav) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function preprocess_wav
refactored with the following changes:
- Merge isinstance calls (
merge-isinstance
)
embed = _model.forward(frames).detach().cpu().numpy() | ||
return embed | ||
return _model.forward(frames).detach().cpu().numpy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function embed_frames_batch
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if return_partials: | ||
return embed, None, None | ||
return embed | ||
|
||
return (embed, None, None) if return_partials else embed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function embed_utterance
refactored with the following changes:
- Lift code into else after jump in control flow [×2] (
reintroduce-else
) - Replace if statement with if expression [×2] (
assign-if-exp
)
if len(speaker_dirs) == 0: | ||
if not speaker_dirs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SpeakerVerificationDataset.__init__
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
)
if preemphasize: | ||
return signal.lfilter([1, -k], [1], wav) | ||
return wav | ||
return signal.lfilter([1, -k], [1], wav) if preemphasize else wav |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function preemphasis
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if inv_preemphasize: | ||
return signal.lfilter([1], [1, -k], wav) | ||
return wav | ||
return signal.lfilter([1], [1, -k], wav) if inv_preemphasize else wav |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function inv_preemphasis
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
|
||
if hparams.signal_normalization: | ||
return _normalize(S, hparams) | ||
return S | ||
|
||
return _normalize(S, hparams) if hparams.signal_normalization else S |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function linearspectrogram
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
|
||
if hparams.signal_normalization: | ||
return _normalize(S, hparams) | ||
return S | ||
|
||
return _normalize(S, hparams) if hparams.signal_normalization else S |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function melspectrogram
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
|
||
S = _db_to_amp(D + hparams.ref_level_db) #Convert back to linear | ||
|
||
if hparams.use_lws: | ||
processor = _lws_processor(hparams) | ||
D = processor.run_lws(S.astype(np.float64).T ** hparams.power) | ||
y = processor.istft(D).astype(np.float32) | ||
return inv_preemphasis(y, hparams.preemphasis, hparams.preemphasize) | ||
else: | ||
|
||
if not hparams.use_lws: | ||
return inv_preemphasis(_griffin_lim(S ** hparams.power, hparams), hparams.preemphasis, hparams.preemphasize) | ||
processor = _lws_processor(hparams) | ||
D = processor.run_lws(S.astype(np.float64).T ** hparams.power) | ||
y = processor.istft(D).astype(np.float32) | ||
return inv_preemphasis(y, hparams.preemphasis, hparams.preemphasize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function inv_linear_spectrogram
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
|
||
S = _mel_to_linear(_db_to_amp(D + hparams.ref_level_db), hparams) # Convert back to linear | ||
|
||
if hparams.use_lws: | ||
processor = _lws_processor(hparams) | ||
D = processor.run_lws(S.astype(np.float64).T ** hparams.power) | ||
y = processor.istft(D).astype(np.float32) | ||
return inv_preemphasis(y, hparams.preemphasis, hparams.preemphasize) | ||
else: | ||
|
||
if not hparams.use_lws: | ||
return inv_preemphasis(_griffin_lim(S ** hparams.power, hparams), hparams.preemphasis, hparams.preemphasize) | ||
processor = _lws_processor(hparams) | ||
D = processor.run_lws(S.astype(np.float64).T ** hparams.power) | ||
y = processor.istft(D).astype(np.float32) | ||
return inv_preemphasis(y, hparams.preemphasis, hparams.preemphasize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function inv_mel_spectrogram
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
for i in range(hparams.griffin_lim_iters): | ||
for _ in range(hparams.griffin_lim_iters): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _griffin_lim
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
if length % fshift == 0: | ||
M = (length + pad * 2 - fsize) // fshift + 1 | ||
else: | ||
M = (length + pad * 2 - fsize) // fshift + 2 | ||
return M | ||
return ( | ||
(length + pad * 2 - fsize) // fshift + 1 | ||
if length % fshift == 0 | ||
else (length + pad * 2 - fsize) // fshift + 2 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function num_frames
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if isinstance(fpath_or_wav, str) or isinstance(fpath_or_wav, Path): | ||
if isinstance(fpath_or_wav, (str, Path)): | ||
wav = Synthesizer.load_preprocess_wav(fpath_or_wav) | ||
else: | ||
wav = fpath_or_wav | ||
|
||
mel_spectrogram = audio.melspectrogram(wav, hparams).astype(np.float32) | ||
return mel_spectrogram | ||
return audio.melspectrogram(wav, hparams).astype(np.float32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Synthesizer.make_spectrogram
refactored with the following changes:
- Merge isinstance calls (
merge-isinstance
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
pronunciation = _get_pronunciation(parts[1]) | ||
if pronunciation: | ||
if pronunciation := _get_pronunciation(parts[1]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _parse_cmudict
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
return match + " dollars" # Unexpected format | ||
return f"{match} dollars" | ||
dollars = int(parts[0]) if parts[0] else 0 | ||
cents = int(parts[1]) if len(parts) > 1 and parts[1] else 0 | ||
if dollars and cents: | ||
dollar_unit = "dollar" if dollars == 1 else "dollars" | ||
cent_unit = "cent" if cents == 1 else "cents" | ||
return "%s %s, %s %s" % (dollars, dollar_unit, cents, cent_unit) | ||
return f"{dollars} {dollar_unit}, {cents} {cent_unit}" | ||
elif dollars: | ||
dollar_unit = "dollar" if dollars == 1 else "dollars" | ||
return "%s %s" % (dollars, dollar_unit) | ||
return f"{dollars} {dollar_unit}" | ||
elif cents: | ||
cent_unit = "cent" if cents == 1 else "cents" | ||
return "%s %s" % (cents, cent_unit) | ||
return f"{cents} {cent_unit}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _expand_dollars
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring
)
This removes the following comments ( why? ):
# Unexpected format
if num > 1000 and num < 3000: | ||
if num == 2000: | ||
return "two thousand" | ||
elif num > 2000 and num < 2010: | ||
return "two thousand " + _inflect.number_to_words(num % 100) | ||
elif num % 100 == 0: | ||
return _inflect.number_to_words(num // 100) + " hundred" | ||
else: | ||
return _inflect.number_to_words(num, andword="", zero="oh", group=2).replace(", ", " ") | ||
else: | ||
if num <= 1000 or num >= 3000: | ||
return _inflect.number_to_words(num, andword="") | ||
if num == 2000: | ||
return "two thousand" | ||
elif num > 2000 and num < 2010: | ||
return f"two thousand {_inflect.number_to_words(num % 100)}" | ||
elif num % 100 == 0: | ||
return f"{_inflect.number_to_words(num // 100)} hundred" | ||
else: | ||
return _inflect.number_to_words(num, andword="", zero="oh", group=2).replace(", ", " ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _expand_number
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
_id_to_symbol = {i: s for i, s in enumerate(symbols)} | ||
_id_to_symbol = dict(enumerate(symbols)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 8-8
refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension
)
cleaner = getattr(cleaners, name) | ||
if not cleaner: | ||
raise Exception("Unknown cleaner: %s" % name) | ||
text = cleaner(text) | ||
if cleaner := getattr(cleaners, name): | ||
text = cleaner(text) | ||
else: | ||
raise Exception(f"Unknown cleaner: {name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _clean_text
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Lift code into else after jump in control flow (
reintroduce-else
) - Swap if/else branches (
swap-if-else-branches
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
return _symbols_to_sequence(["@" + s for s in text.split()]) | ||
return _symbols_to_sequence([f"@{s}" for s in text.split()]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _arpabet_to_sequence
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
self.ui.log("Exception: %s" % exc_value) | ||
self.ui.log(f"Exception: {exc_value}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Toolbox.excepthook
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
speaker_name = self.ui.current_dataset_name + '_' + self.ui.current_speaker_name | ||
speaker_name = f'{self.ui.current_dataset_name}_{self.ui.current_speaker_name}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Toolbox.load_from_browser
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
self.ui.log("Loading the encoder %s... " % model_fpath) | ||
self.ui.log(f"Loading the encoder {model_fpath}... ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Toolbox.init_encoder
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
self.ui.log("Loading the synthesizer %s... " % model_fpath) | ||
self.ui.log(f"Loading the synthesizer {model_fpath}... ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Toolbox.init_synthesizer
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
def time_since(started) : | ||
def time_since(started): | ||
elapsed = time.time() - started | ||
m = int(elapsed // 60) | ||
s = int(elapsed % 60) | ||
if m >= 60 : | ||
h = int(m // 60) | ||
m = m % 60 | ||
return f'{h}h {m}m {s}s' | ||
else : | ||
if m < 60: | ||
return f'{m}m {s}s' | ||
h = int(m // 60) | ||
m %= 60 | ||
return f'{h}h {m}m {s}s' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function time_since
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Replace assignment with augmented assignment (
aug-assign
)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function load_model
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
|
||
if normalize: | ||
mel = mel / hp.mel_max_abs_value | ||
mel = torch.from_numpy(mel[None, ...]) | ||
wav = _model.generate(mel, batched, target, overlap, hp.mu_law, progress_callback) | ||
return wav | ||
return _model.generate( | ||
mel, batched, target, overlap, hp.mu_law, progress_callback | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function infer_waveform
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
def num_params(self) : | ||
def num_params(self): | ||
parameters = filter(lambda p: p.requires_grad, self.parameters()) | ||
parameters = sum([np.prod(p.size()) for p in parameters]) / 1_000_000 | ||
parameters = sum(np.prod(p.size()) for p in parameters) / 1_000_000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function WaveRNN.num_params
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
)
for i in range(res_blocks): | ||
for _ in range(res_blocks): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function MelResNet.__init__
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run: