Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SourceryAI
Copy link

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:

git fetch https://github.com/sourcery-ai-bot/Real-Time-Voice-Cloning master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Copy link
Author

@SourceryAI SourceryAI left a 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)}")
Copy link
Author

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:

@@ -5,6 +5,7 @@


if __name__ == "__main__":

Copy link
Author

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:

Comment on lines -35 to +49
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)

Copy link
Author

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:

embed = _model.forward(frames).detach().cpu().numpy()
return embed
return _model.forward(frames).detach().cpu().numpy()
Copy link
Author

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:

Comment on lines -133 to +132
if return_partials:
return embed, None, None
return embed

return (embed, None, None) if return_partials else embed
Copy link
Author

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:

if len(speaker_dirs) == 0:
if not speaker_dirs:
Copy link
Author

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:

if preemphasize:
return signal.lfilter([1, -k], [1], wav)
return wav
return signal.lfilter([1, -k], [1], wav) if preemphasize else wav
Copy link
Author

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:

Comment on lines -26 to +24
if inv_preemphasize:
return signal.lfilter([1], [1, -k], wav)
return wav
return signal.lfilter([1], [1, -k], wav) if inv_preemphasize else wav
Copy link
Author

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:

Comment on lines -54 to +51

if hparams.signal_normalization:
return _normalize(S, hparams)
return S

return _normalize(S, hparams) if hparams.signal_normalization else S
Copy link
Author

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:

Comment on lines -62 to +57

if hparams.signal_normalization:
return _normalize(S, hparams)
return S

return _normalize(S, hparams) if hparams.signal_normalization else S
Copy link
Author

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:


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)
Copy link
Author

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:

Comment on lines -90 to +89

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)
Copy link
Author

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:

Comment on lines -112 to +102
for i in range(hparams.griffin_lim_iters):
for _ in range(hparams.griffin_lim_iters):
Copy link
Author

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:

Comment on lines -132 to +126
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
)
Copy link
Author

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:

Comment on lines -147 to +152
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)
Copy link
Author

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:

pronunciation = _get_pronunciation(parts[1])
if pronunciation:
if pronunciation := _get_pronunciation(parts[1]):
Copy link
Author

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:

Comment on lines -26 to +38
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}"
Copy link
Author

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:

This removes the following comments ( why? ):

# Unexpected format

Comment on lines -49 to +58
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(", ", " ")
Copy link
Author

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:

_id_to_symbol = {i: s for i, s in enumerate(symbols)}
_id_to_symbol = dict(enumerate(symbols))
Copy link
Author

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:

Comment on lines -59 to +62
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}")
Copy link
Author

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:

return _symbols_to_sequence(["@" + s for s in text.split()])
return _symbols_to_sequence([f"@{s}" for s in text.split()])
Copy link
Author

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:

self.ui.log("Exception: %s" % exc_value)
self.ui.log(f"Exception: {exc_value}")
Copy link
Author

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:

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}'
Copy link
Author

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:

self.ui.log("Loading the encoder %s... " % model_fpath)
self.ui.log(f"Loading the encoder {model_fpath}... ")
Copy link
Author

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:

self.ui.log("Loading the synthesizer %s... " % model_fpath)
self.ui.log(f"Loading the synthesizer {model_fpath}... ")
Copy link
Author

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:

Comment on lines -74 to +79
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'
Copy link
Author

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:


Copy link
Author

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:

Comment on lines -59 to +65

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
)
Copy link
Author

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:

Comment on lines -167 to +169
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
Copy link
Author

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:

for i in range(res_blocks):
for _ in range(res_blocks):
Copy link
Author

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant