Example #1
0
    def __getitem__(self, index):
        example = self.collection[index]
        features = AudioSegment.segment_from_file(
            example.audio_file,
            n_segments=self.n_segments,
            trim=self.trim,
        )
        features = torch.tensor(features.samples, dtype=torch.float)
        f, fl = features, torch.tensor(features.shape[0]).long()

        return f, fl
Example #2
0
    def __getitem__(self, index):
        """
        Given a index, returns audio and audio_length of the corresponding element. Audio clips of n_segments are
        randomly chosen if the audio is longer than n_segments.
        """
        example = self.collection[index]
        features = AudioSegment.segment_from_file(example.audio_file, n_segments=self.n_segments, trim=self.trim,)
        features = torch.tensor(features.samples)
        audio, audio_length = features, torch.tensor(features.shape[0]).long()

        truncate = audio_length % self.truncate_to
        if truncate != 0:
            audio_length -= truncate.long()
            audio = audio[:audio_length]

        return audio, audio_length