fix train.py
Browse files
train.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import torch
|
| 2 |
from dataclasses import dataclass
|
| 3 |
from typing import Any
|
|
@@ -39,9 +40,16 @@ class DataCollatorCTCWithPadding:
|
|
| 39 |
|
| 40 |
def prepare_dataset(batch, processor):
|
| 41 |
audio = batch["audio"]
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
batch["input_length"] = len(batch["input_values"])
|
| 46 |
batch["labels"] = processor(text=batch["normalized_text"]).input_ids
|
| 47 |
return batch
|
|
|
|
| 1 |
+
import librosa
|
| 2 |
import torch
|
| 3 |
from dataclasses import dataclass
|
| 4 |
from typing import Any
|
|
|
|
| 40 |
|
| 41 |
def prepare_dataset(batch, processor):
|
| 42 |
audio = batch["audio"]
|
| 43 |
+
target_sr = processor.feature_extractor.sampling_rate
|
| 44 |
+
array = audio["array"]
|
| 45 |
+
if audio["sampling_rate"] != target_sr:
|
| 46 |
+
array = librosa.resample(
|
| 47 |
+
array,
|
| 48 |
+
orig_sr=audio["sampling_rate"],
|
| 49 |
+
target_sr=target_sr,
|
| 50 |
+
res_type="kaiser_fast",
|
| 51 |
+
)
|
| 52 |
+
batch["input_values"] = processor(array, sampling_rate=target_sr).input_values[0]
|
| 53 |
batch["input_length"] = len(batch["input_values"])
|
| 54 |
batch["labels"] = processor(text=batch["normalized_text"]).input_ids
|
| 55 |
return batch
|