Update eduport_tts_mal.py
Browse files- eduport_tts_mal.py +2 -19
eduport_tts_mal.py
CHANGED
@@ -10,7 +10,6 @@ from torchaudio.transforms import Resample
|
|
10 |
from torch.amp import GradScaler, autocast
|
11 |
from tqdm import tqdm
|
12 |
from jiwer import wer
|
13 |
-
from torchaudio.transforms import TimeStretch, PitchShift
|
14 |
from safetensors.torch import save_file
|
15 |
|
16 |
# Compute max audio length from the training dataset
|
@@ -69,22 +68,6 @@ class SpeechDataset(Dataset):
|
|
69 |
input_ids = self.tokenizer.encode(transcript, truncation=True, padding='longest', max_length=self.max_length, return_tensors="pt").squeeze(0)
|
70 |
|
71 |
return input_values, input_ids
|
72 |
-
|
73 |
-
class AugmentedSpeechDataset(SpeechDataset):
|
74 |
-
def __getitem__(self, idx):
|
75 |
-
input_values, input_ids = super().__getitem__(idx)
|
76 |
-
|
77 |
-
# Random time stretching
|
78 |
-
if torch.rand(1).item() < 0.3:
|
79 |
-
time_stretch = TimeStretch(factor=torch.uniform(0.8, 1.2))
|
80 |
-
input_values = time_stretch(input_values)
|
81 |
-
|
82 |
-
# Random pitch shift
|
83 |
-
if torch.rand(1).item() < 0.3:
|
84 |
-
pitch_shift = PitchShift(sample_rate=self.target_sampling_rate, n_steps=torch.randint(-2, 2, (1,)))
|
85 |
-
input_values = pitch_shift(input_values)
|
86 |
-
|
87 |
-
return input_values, input_ids
|
88 |
|
89 |
def collate_fn(batch):
|
90 |
audio_inputs, text_inputs = zip(*batch)
|
@@ -122,8 +105,8 @@ print(max_audio_length)
|
|
122 |
train_audios, val_audios, train_transcripts, val_transcripts = train_test_split(audio_files, transcript_files, test_size=0.05, random_state=42)
|
123 |
|
124 |
# Define your dataset and dataloaders
|
125 |
-
train_dataset =
|
126 |
-
val_dataset =
|
127 |
|
128 |
# Update your DataLoader to use the custom collate_fn
|
129 |
train_loader = DataLoader(train_dataset, batch_size=1, shuffle=True, collate_fn=collate_fn)
|
|
|
10 |
from torch.amp import GradScaler, autocast
|
11 |
from tqdm import tqdm
|
12 |
from jiwer import wer
|
|
|
13 |
from safetensors.torch import save_file
|
14 |
|
15 |
# Compute max audio length from the training dataset
|
|
|
68 |
input_ids = self.tokenizer.encode(transcript, truncation=True, padding='longest', max_length=self.max_length, return_tensors="pt").squeeze(0)
|
69 |
|
70 |
return input_values, input_ids
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
def collate_fn(batch):
|
73 |
audio_inputs, text_inputs = zip(*batch)
|
|
|
105 |
train_audios, val_audios, train_transcripts, val_transcripts = train_test_split(audio_files, transcript_files, test_size=0.05, random_state=42)
|
106 |
|
107 |
# Define your dataset and dataloaders
|
108 |
+
train_dataset = SpeechDataset(train_audios, train_transcripts, tokenizer, processor, max_audio_length=max_audio_length)
|
109 |
+
val_dataset = SpeechDataset(val_audios, val_transcripts, tokenizer, processor, max_audio_length=max_audio_length)
|
110 |
|
111 |
# Update your DataLoader to use the custom collate_fn
|
112 |
train_loader = DataLoader(train_dataset, batch_size=1, shuffle=True, collate_fn=collate_fn)
|