示例#1
0
 def stft_to_feature(self, stft_signals):
     if pt_complex.is_torch(stft_signals):
         concatenate = torch.cat
     else:
         concatenate = np.concatenate
     return concatenate([
         abs(stft_signals),
         stft_signals.real,
         stft_signals.imag,
     ],
                        axis=-1)
示例#2
0
 def stft_to_feature(self, stft_signals):
     if pt_complex.is_torch(stft_signals):
         raise NotImplementedError()
         return torch.log1p(abs(stft_signals))
     else:
         angle = np.angle(stft_signals)
         return np.concatenate([
             np.log1p(abs(stft_signals)),
             np.cos(angle),
             np.sin(angle),
         ],
                               axis=-1)
示例#3
0
    def stft(self, signal):
        kwargs = dict(
            size=self.size,
            shift=self.shift,
            axis=-1,
            window_length=self.window_length,
            window=self._window,
            fading=self.fading,
            pad=self.pad,
            # symmetric_window=False,
        )

        if pt_complex.is_torch(signal):
            return pt_stft(signal, **kwargs)
        else:
            return pb.transform.stft(signal, **kwargs)
示例#4
0
 def stft_to_feature(self, stft_signals):
     if pt_complex.is_torch(stft_signals):
         return torch.log1p(abs(stft_signals))
     else:
         return np.log1p(abs(stft_signals))
示例#5
0
    def istft(self, signal, num_samples=None):
        """

        Args:
            signal:
            samples:

        Returns:

        >>> def print_properties(array):
        ...     print(f'array(shape={array.shape}, dtype={array.dtype})')


        >>> fe_stft = STFT()
        >>> fe_stft
        STFT(size=1024, shift=256, window_length=1024, pad=True, fading=True, output_size=513, window='blackman')


        >>> audio = pb.io.load('/net/vol/jenkins/python_unittest_data/timit/data/sample_1.wav')
        >>> print_properties(audio)
        array(shape=(46797,), dtype=float64)
        >>> samples, = audio.shape

        >>> print_properties(fe_stft([audio]))
        array(shape=(1, 186, 513), dtype=complex128)
        >>> print_properties(fe_stft.istft(fe_stft([audio])))
        array(shape=(1, 46848), dtype=float64)
        >>> print_properties(fe_stft.istft(fe_stft([audio]), num_samples=samples))
        array(shape=(1, 46797), dtype=float64)

        >>> print_properties(fe_stft.istft(fe_stft(np.zeros([1023]))))
        array(shape=(1024,), dtype=float64)
        >>> print_properties(fe_stft.istft(fe_stft(np.zeros([1024]))))
        array(shape=(1024,), dtype=float64)
        >>> print_properties(fe_stft.istft(fe_stft(np.zeros([1025]))))
        array(shape=(1280,), dtype=float64)
        >>> print_properties(fe_stft.istft(fe_stft(np.zeros([1023])), num_samples=1023))
        array(shape=(1023,), dtype=float64)
        >>> print_properties(fe_stft.istft(fe_stft(np.zeros([1024])), num_samples=1024))
        array(shape=(1024,), dtype=float64)
        >>> print_properties(fe_stft.istft(fe_stft(np.zeros([1025])), num_samples=1025))
        array(shape=(1025,), dtype=float64)

        """
        kwargs = dict(
            size=self.size,
            shift=self.shift,
            # axis=axis,
            window=self._window,
            window_length=self.window_length,
            fading=self.fading,
            pad=self.pad,
            # symmetric_window=False,
            # dft_norm=self.dft_norm,
            num_samples=num_samples,
        )

        if pt_complex.is_torch(signal):
            time_signal = pt_istft(signal, **kwargs)
        else:
            time_signal = pb.transform.istft(signal, **kwargs)

        return time_signal