def separate_effective(self, wave: Wave, feature: AcousticFeature, threshold=None): """ :return: (effective feature, effective flags) """ hop, length = wave.get_hop_and_length( frame_period=self._param.frame_period) if threshold is None: if self._param.threshold_db is not None: effective = wave.get_effective_frame( threshold_db=self._param.threshold_db, fft_length=self._param.fft_length, frame_period=self._param.frame_period, ) feature = feature.indexing(effective) else: effective = numpy.ones(length, dtype=bool) else: mse = librosa.feature.rmse(y=wave.wave, frame_length=self._param.fft_length, hop_length=hop)**2 effective = (librosa.core.power_to_db(mse.squeeze()) > -threshold) if len(effective) < len(feature.f0): # the divide move effective = numpy.r_[effective, False] if len(effective) > len(feature.f0): # the divide move effective = effective if len(effective) < len(feature.f0): # the divide move effective = numpy.r_[effective, False] if len(effective) > len(feature.f0): # the divide move effective = effective feature = feature.indexing(effective) return feature, effective
def convert_loop(self, in_feature: AcousticFeature, n_len: int = 512, n_wrap: int = 128): out_feature_list: List[AcousticFeature] = [] N = len(in_feature.f0) for i in numpy.arange(0, int(numpy.ceil(N / n_len))): # convert with overwrapped start = i * n_len mi = max(start - n_wrap, 0) ma = min(start + n_len + n_wrap, N) f = in_feature.indexing(numpy.arange(mi, ma)) o_warp = self.convert(f) # eliminate overwrap ex_mi = start - mi ex_len = min(ma - start, n_len) o = o_warp.indexing(numpy.arange(ex_mi, ex_mi + ex_len)) out_feature_list.append(o) return AcousticFeature.concatenate(out_feature_list)