⚗️ | Experiment with other layer layouts.
This commit is contained in:
25
data.py
25
data.py
@ -19,26 +19,25 @@ class AudioDataset(Dataset):
|
||||
|
||||
|
||||
def __getitem__(self, idx):
|
||||
high_quality_wav, sr_original = torchaudio.load(self.input_files[idx], normalize=True)
|
||||
high_quality_audio, original_sample_rate = torchaudio.load(self.input_files[idx], normalize=True)
|
||||
|
||||
sample_rate = random.choice(self.audio_sample_rates)
|
||||
resample_transform = torchaudio.transforms.Resample(sr_original, sample_rate)
|
||||
low_quality_wav = resample_transform(high_quality_wav)
|
||||
low_quality_wav = low_quality_wav
|
||||
mangled_sample_rate = random.choice(self.audio_sample_rates)
|
||||
resample_transform = torchaudio.transforms.Resample(original_sample_rate, mangled_sample_rate)
|
||||
low_quality_audio = resample_transform(high_quality_audio)
|
||||
|
||||
# Calculate target length based on desired duration and 16000 Hz
|
||||
if self.target_duration is not None:
|
||||
target_length = int(self.target_duration * 44100)
|
||||
else:
|
||||
# Calculate duration of original high quality audio
|
||||
target_length = high_quality_wav.size(1)
|
||||
# if self.target_duration is not None:
|
||||
# target_length = int(self.target_duration * 44100)
|
||||
# else:
|
||||
# # Calculate duration of original high quality audio
|
||||
# target_length = high_quality_wav.size(1)
|
||||
|
||||
# Pad both to the calculated target length
|
||||
high_quality_wav = self.stretch_tensor(high_quality_wav, target_length)
|
||||
low_quality_wav = self.stretch_tensor(low_quality_wav, target_length)
|
||||
# high_quality_wav = self.stretch_tensor(high_quality_wav, target_length)
|
||||
# low_quality_wav = self.stretch_tensor(low_quality_wav, target_length)
|
||||
|
||||
|
||||
return low_quality_wav, high_quality_wav
|
||||
return (high_quality_audio, original_sample_rate), (low_quality_audio, mangled_sample_rate)
|
||||
|
||||
def stretch_tensor(self, tensor, target_length):
|
||||
current_length = tensor.size(1)
|
||||
|
Reference in New Issue
Block a user