Example #1
0
 def _decode_feature(self, data):
     sizes = AcousticFeature.get_sizes(
         sampling_rate=self._param.sampling_rate,
         order=self._param.order,
     )
     return decode_feature(data,
                           targets=self.config.dataset.out_features,
                           sizes=sizes)
Example #2
0
 def combine_silent(self, effective: numpy.ndarray, feature: AcousticFeature):
     sizes = AcousticFeature.get_sizes(
         sampling_rate=self._param.sampling_rate,
         order=self._param.order,
     )
     silent_feature = AcousticFeature.silent(len(effective), sizes=sizes, keys=('mc', 'ap', 'f0', 'voiced'))
     silent_feature.indexing_set(effective, feature)
     return silent_feature
Example #3
0
 def pad(self, width: int):
     sizes = AcousticFeature.get_sizes(
         sampling_rate=self.wave_sampling_rate, order=self.order)
     return AcousticFeatureWrapper.silent_wrapper(
         width,
         sizes=sizes,
         keys=self._keys,
         frame_period=self.frame_period,
         sampling_rate=self.wave_sampling_rate,
         wave_dtype=numpy.float32,
     ).astype_only_float_wrapper(numpy.float32)
Example #4
0
    def post_convert(self, start_time: float, time_length: float):
        sizes = AcousticFeature.get_sizes(sampling_rate=self.sampling_rate, order=self.order)
        keys = ['f0', 'ap', 'sp', 'voiced']
        out_feature = self.fetch(
            start_time=start_time,
            time_length=time_length,
            data_stream=self._out_feature_stream,
            rate=1000 / self.frame_period,
            pad_function=lambda length: AcousticFeature.silent(length, sizes=sizes, keys=keys),
            pick_function=lambda segment, first, last: segment.feature.pick(first, last, keys=keys),
            concat_function=lambda buffers: AcousticFeature.concatenate(buffers, keys=keys),
        )

        out_wave = self.vocoder.decode(
            acoustic_feature=out_feature,
        )

        w = out_wave.wave
        w[numpy.isnan(w)] = 0
        out_wave = Wave(wave=w, sampling_rate=out_wave.sampling_rate)
        return out_wave
Example #5
0
    def convert(self, start_time: float, time_length: float, extra_time: float):
        sizes = AcousticFeature.get_sizes(sampling_rate=self.sampling_rate, order=self.order)
        keys = ['f0', 'ap', 'mc', 'voiced']

        def _pad_function(length):
            return AcousticFeatureWrapper.silent_wrapper(
                length,
                sizes=sizes,
                keys=keys,
                frame_period=self.frame_period,
                sampling_rate=self.sampling_rate,
                wave_dtype=self.in_dtype,
            ).astype_only_float_wrapper(self.in_dtype)

        def _pick_function(segment: FeatureWrapperSegment, first, last):
            return segment.feature.pick_wrapper(
                first,
                last,
                keys=keys,
                frame_period=self.frame_period,
            )

        in_feature = self.fetch(
            start_time=start_time,
            time_length=time_length,
            extra_time=extra_time,
            data_stream=self._in_feature_stream,
            rate=1000 / self.frame_period,
            pad_function=_pad_function,
            pick_function=_pick_function,
            concat_function=lambda buffers: AcousticFeatureWrapper.concatenate_wrapper(buffers, keys=keys),
        )
        out_feature = self.voice_changer.convert_from_acoustic_feature(in_feature)

        pad = round(extra_time * 1000 / self.frame_period)
        out_feature = out_feature.pick(pad, -pad, keys=['f0', 'ap', 'sp', 'voiced'])
        return out_feature
Example #6
0
 def pad(self, width: int):
     sizes = AcousticFeature.get_sizes(
         sampling_rate=self.wave_sampling_rate, order=self.order)
     return AcousticFeature.silent(width, sizes=sizes, keys=self._keys)