From ad64d797375e5a7239d4383fe17a345aac920bb8 Mon Sep 17 00:00:00 2001 From: yxlllc Date: Mon, 3 Aug 2026 00:44:42 +0800 Subject: [PATCH 1/3] some minor fixes --- inference/ds_variance.py | 5 +++-- preprocessing/acoustic_binarizer.py | 2 +- preprocessing/variance_binarizer.py | 15 +++++++++++---- utils/infer_utils.py | 8 +------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/inference/ds_variance.py b/inference/ds_variance.py index da3d6e94d..cb682fd93 100644 --- a/inference/ds_variance.py +++ b/inference/ds_variance.py @@ -241,14 +241,15 @@ def preprocess_input( batch['midi'] = ph_midi if load_pitch: + # Interpolate unvoiced parts before resampling. f0 = resample_align_curve( - np.array(param['f0_seq'].split(), np.float32), + interp_f0(np.array(param['f0_seq'].split(), np.float32))[0], original_timestep=float(param['f0_timestep']), target_timestep=self.timestep, align_length=T_s ) batch['pitch'] = torch.from_numpy( - librosa.hz_to_midi(interp_f0(f0)[0]).astype(np.float32) + librosa.hz_to_midi(f0).astype(np.float32) ).to(self.device)[None] if self.model.predict_dur: diff --git a/preprocessing/acoustic_binarizer.py b/preprocessing/acoustic_binarizer.py index 9301f14bc..16ad953a0 100644 --- a/preprocessing/acoustic_binarizer.py +++ b/preprocessing/acoustic_binarizer.py @@ -337,7 +337,7 @@ def arrange_data_augmentation(self, data_iterator): aug_list.append(aug_task) elif aug_type == 1: aug_task = { - 'name': aug_item, + 'name': aug_item['name'], 'func': aug_item['func'], 'kwargs': deepcopy(aug_item['kwargs']) } diff --git a/preprocessing/variance_binarizer.py b/preprocessing/variance_binarizer.py index 3d2990fe4..589bf571a 100644 --- a/preprocessing/variance_binarizer.py +++ b/preprocessing/variance_binarizer.py @@ -314,14 +314,21 @@ def process_item(self, item_name, meta_data, binarization_args): if self.prefer_ds: f0_seq = self.load_attr_from_ds(ds_id, name, 'f0_seq', idx=ds_seg_idx) if f0_seq is not None: + f0_timestep = float(self.load_attr_from_ds(ds_id, name, 'f0_timestep', idx=ds_seg_idx)) + # Interpolate unvoiced parts before resampling. + f0_points, uv_points = interp_f0(np.array(f0_seq.split(), np.float32)) f0 = resample_align_curve( - np.array(f0_seq.split(), np.float32), - original_timestep=float(self.load_attr_from_ds(ds_id, name, 'f0_timestep', idx=ds_seg_idx)), + f0_points, + original_timestep=f0_timestep, target_timestep=self.timestep, align_length=length ) - uv = f0 == 0 - f0, _ = interp_f0(f0, uv) + uv = resample_align_curve( + uv_points.astype(np.float32), + original_timestep=f0_timestep, + target_timestep=self.timestep, + align_length=length + ) > 0.5 if f0 is None: f0, uv = pitch_extractor.get_pitch( waveform, samplerate=hparams['audio_sample_rate'], length=length, diff --git a/utils/infer_utils.py b/utils/infer_utils.py index 7dc32c2ee..ec649b7a8 100644 --- a/utils/infer_utils.py +++ b/utils/infer_utils.py @@ -39,17 +39,11 @@ def trans_key(raw_data, key): def resample_align_curve(points: np.ndarray, original_timestep: float, target_timestep: float, align_length: int): - t_max = (len(points) - 1) * original_timestep curve_interp = np.interp( - np.arange(0, t_max, target_timestep), + np.arange(align_length) * target_timestep, original_timestep * np.arange(len(points)), points ).astype(points.dtype) - delta_l = align_length - len(curve_interp) - if delta_l < 0: - curve_interp = curve_interp[:align_length] - elif delta_l > 0: - curve_interp = np.concatenate((curve_interp, np.full(delta_l, fill_value=curve_interp[-1])), axis=0) return curve_interp From 25bb493188b897bc734435328afee17f8655789b Mon Sep 17 00:00:00 2001 From: yxlllc Date: Sun, 9 Aug 2026 20:24:47 +0800 Subject: [PATCH 2/3] some minor fixes --- inference/ds_variance.py | 25 ++++++++++++------------- modules/toplevel.py | 5 ++++- preprocessing/acoustic_binarizer.py | 3 ++- utils/decomposed_waveform.py | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/inference/ds_variance.py b/inference/ds_variance.py index cb682fd93..f2821e2e9 100644 --- a/inference/ds_variance.py +++ b/inference/ds_variance.py @@ -443,19 +443,18 @@ def run_inference( param_copy[f'{v_name}_timestep'] = str(self.timestep) # Restore ph_spk_mix and spk_mix - if 'ph_spk_mix' in param_copy and 'spk_mix' in param_copy: - if 'ph_spk_mix_backup' in param_copy: - if param_copy['ph_spk_mix_backup'] is None: - del param_copy['ph_spk_mix'] - else: - param_copy['ph_spk_mix'] = param_copy['ph_spk_mix_backup'] - del param['ph_spk_mix_backup'] - if 'spk_mix_backup' in param_copy: - if param_copy['ph_spk_mix_backup'] is None: - del param_copy['spk_mix'] - else: - param_copy['spk_mix'] = param_copy['spk_mix_backup'] - del param['spk_mix_backup'] + if 'ph_spk_mix_backup' in param_copy: + if param_copy['ph_spk_mix_backup'] is None: + param_copy.pop('ph_spk_mix', None) + else: + param_copy['ph_spk_mix'] = param_copy['ph_spk_mix_backup'] + del param_copy['ph_spk_mix_backup'] + if 'spk_mix_backup' in param_copy: + if param_copy['spk_mix_backup'] is None: + param_copy.pop('spk_mix', None) + else: + param_copy['spk_mix'] = param_copy['spk_mix_backup'] + del param_copy['spk_mix_backup'] results.append(param_copy) diff --git a/modules/toplevel.py b/modules/toplevel.py index 4a97b3c91..ebe9a9bc8 100644 --- a/modules/toplevel.py +++ b/modules/toplevel.py @@ -341,7 +341,10 @@ def forward( return dur_pred_out, pitch_pred_out, ({} if infer else None) if pitch is None: - pitch = base_pitch + pitch_pred_out + if pitch_pred_out is not None: + pitch = base_pitch + pitch_pred_out + else: + pitch = base_pitch if self.use_variance_scaling: var_cond = condition + self.pitch_embed(pitch[:, :, None] / 12) else: diff --git a/preprocessing/acoustic_binarizer.py b/preprocessing/acoustic_binarizer.py index 16ad953a0..61c74f9aa 100644 --- a/preprocessing/acoustic_binarizer.py +++ b/preprocessing/acoustic_binarizer.py @@ -319,7 +319,8 @@ def arrange_data_augmentation(self, data_iterator): k_from_aug = int(total_scale * scale / (1 + total_scale) * len(all_item_names)) k_mutate = int(total_scale * scale / (1 + scale) * len(all_item_names)) aug_types = [0] * k_from_raw + [1] * k_from_aug + [2] * k_mutate - aug_items = random.choices(all_item_names, k=k_from_raw) + random.choices(aug_list, k=k_from_aug + k_mutate) + aug_items = random.choices(all_item_names, k=k_from_raw) + \ + random.choices(aug_list, k=k_from_aug) + random.sample(aug_list, k=k_mutate) for aug_type, aug_item in zip(aug_types, aug_items): # Uniform distribution in log domain diff --git a/utils/decomposed_waveform.py b/utils/decomposed_waveform.py index cfccb0e17..593bf868f 100644 --- a/utils/decomposed_waveform.py +++ b/utils/decomposed_waveform.py @@ -75,7 +75,7 @@ def _init( # extraction parameters self._hop_size = hop_size self._fft_size = fft_size if fft_size is not None else win_size - self._win_size = win_size if win_size is not None else win_size + self._win_size = win_size if win_size is not None else fft_size self._time_step = hop_size / samplerate self._half_width = base_harmonic_radius self._device = ('cuda' if torch.cuda.is_available() else 'cpu') if device is None else device From b3d54d3b910bd6abd5d81259187393f8661da71e Mon Sep 17 00:00:00 2001 From: yxlllc Date: Sun, 9 Aug 2026 21:27:08 +0800 Subject: [PATCH 3/3] fix --- preprocessing/acoustic_binarizer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessing/acoustic_binarizer.py b/preprocessing/acoustic_binarizer.py index 61c74f9aa..dff5e679b 100644 --- a/preprocessing/acoustic_binarizer.py +++ b/preprocessing/acoustic_binarizer.py @@ -320,7 +320,7 @@ def arrange_data_augmentation(self, data_iterator): k_mutate = int(total_scale * scale / (1 + scale) * len(all_item_names)) aug_types = [0] * k_from_raw + [1] * k_from_aug + [2] * k_mutate aug_items = random.choices(all_item_names, k=k_from_raw) + \ - random.choices(aug_list, k=k_from_aug) + random.sample(aug_list, k=k_mutate) + random.choices(aug_list, k=k_from_aug) + random.sample(aug_list, k=min(k_mutate, len(aug_list))) for aug_type, aug_item in zip(aug_types, aug_items): # Uniform distribution in log domain