예제 #1
0
    def __init__(
        self,
        mixture_path: str,
        audio_sample_rate: int,
        sample_length: int,
        stft_n_fft: int,
        stft_win_length: int,
        stft_hop: int,
        device: torch.device = torch.device("cpu")) -> None:
        self.sample_length: int = sample_length
        self.audio_sample_rate: int = audio_sample_rate
        self.stft_n_fft: int = stft_n_fft
        self.stft_win_length = stft_win_length
        self.stft_hop: int = stft_hop

        waveform_length = Audio.calc_waveform_length(mixture_path,
                                                     audio_sample_rate)
        self.samples_count = Audio.calc_stft_length(waveform_length, stft_hop)

        self.waveform = Audio.load(mixture_path,
                                   sample_rate=audio_sample_rate,
                                   device=device)
        self.amplitude, self.phase = Audio.compute_stft(
            self.waveform, self.stft_n_fft, self.stft_win_length,
            self.stft_hop)
예제 #2
0
    def __init__(
        self,
        data_frame: pandas.DataFrame,
        audio_sample_rate: int,
        sample_length: int,
        stft_n_fft: int,
        stft_win_length: int,
        stft_hop: int,
        shuffle: bool = False,
        seed: Any = None,
        device: torch.device = torch.device("cpu")) -> None:
        self.data = pandas.DataFrame()
        self.audio_sample_rate: int = audio_sample_rate
        self.sample_length: int = sample_length
        self.stft_n_fft: int = stft_n_fft
        self.stft_win_length: int = stft_win_length
        self.stft_hop: int = stft_hop
        self.shuffle: bool = shuffle
        self.seed: Any = seed if (seed is not None) else random.random()
        self.device = device

        for i, row in data_frame.iterrows():
            new_row = dict()

            for col in ["mixture", "vocals", "accompaniment"]:
                path = pathlib.Path(row[col]).absolute()
                if not path.exists() or path.is_dir():
                    raise FileNotFoundError(path)
                new_row[col] = str(path)

            waveform_length = Audio.calc_waveform_length(
                row["mixture"], self.audio_sample_rate)
            stft_length = Audio.calc_stft_length(waveform_length,
                                                 self.stft_hop)
            new_row["n_frames"] = stft_length

            self.data = self.data.append(new_row, ignore_index=True)