Skip to content

Commit

Permalink
Speed up training by loading all audio in RAM.
Browse files Browse the repository at this point in the history
This fixes descriptinc#19
  • Loading branch information
fdb committed Mar 20, 2023
1 parent 76a2734 commit b8a0ff8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions mel2wav/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ def __init__(self, training_files, segment_length, sampling_rate, augment=True):
random.shuffle(self.audio_files)
self.augment = augment

# Load all audio files into memory
self.audio_data = []
for audio_file in self.audio_files:
audio, _ = self.load_wav_to_torch(audio_file)
self.audio_data.append(audio)

def __getitem__(self, index):
# Read audio
filename = self.audio_files[index]
audio, sampling_rate = self.load_wav_to_torch(filename)
# Get audio from memory
audio = self.audio_data[index]

# Take segment
if audio.size(0) >= self.segment_length:
max_audio_start = audio.size(0) - self.segment_length
Expand Down

0 comments on commit b8a0ff8

Please sign in to comment.