Add train_narrator_tts.py
Browse files- train_narrator_tts.py +12 -19
train_narrator_tts.py
CHANGED
|
@@ -56,6 +56,7 @@ MAX_SECS = 12.0
|
|
| 56 |
|
| 57 |
DATASET_NAME = "narrator"
|
| 58 |
EXP_ARCH = "F5TTS_v1_Base"
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
def _lib_root() -> Path:
|
|
@@ -87,12 +88,12 @@ def prepare_data() -> None:
|
|
| 87 |
tar.extractall("/tmp/", filter="data")
|
| 88 |
print(f"Extracted -> {lj_root}")
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
#
|
| 93 |
-
# row["
|
| 94 |
-
#
|
| 95 |
-
|
| 96 |
texts: list[str] = []
|
| 97 |
durations: list[float] = []
|
| 98 |
count = 0
|
|
@@ -122,7 +123,9 @@ def prepare_data() -> None:
|
|
| 122 |
import librosa
|
| 123 |
arr = librosa.resample(arr, orig_sr=orig_sr, target_sr=TARGET_SR)
|
| 124 |
|
| 125 |
-
|
|
|
|
|
|
|
| 126 |
texts.append(text)
|
| 127 |
durations.append(len(arr) / TARGET_SR)
|
| 128 |
count += 1
|
|
@@ -135,7 +138,8 @@ def prepare_data() -> None:
|
|
| 135 |
raw_dir = token_dir / "raw"
|
| 136 |
raw_dir.mkdir(parents=True, exist_ok=True)
|
| 137 |
|
| 138 |
-
|
|
|
|
| 139 |
ds.save_to_disk(str(raw_dir))
|
| 140 |
print(f"Saved dataset -> {raw_dir}")
|
| 141 |
|
|
@@ -210,17 +214,6 @@ def push_model(ckpt_dir: Path) -> None:
|
|
| 210 |
|
| 211 |
|
| 212 |
if __name__ == "__main__":
|
| 213 |
-
# torchcodec (datasets audio decoder) needs FFmpeg system libs — install before training
|
| 214 |
-
print("Installing FFmpeg for torchcodec audio decoding...")
|
| 215 |
-
r = subprocess.run(
|
| 216 |
-
["apt-get", "install", "-y", "--no-install-recommends", "ffmpeg"],
|
| 217 |
-
capture_output=True, text=True,
|
| 218 |
-
)
|
| 219 |
-
if r.returncode == 0:
|
| 220 |
-
print("FFmpeg installed OK")
|
| 221 |
-
else:
|
| 222 |
-
print(f"apt-get failed (rc={r.returncode}): {r.stderr[-300:]}")
|
| 223 |
-
|
| 224 |
prepare_data()
|
| 225 |
ckpt_dir = fine_tune()
|
| 226 |
push_model(ckpt_dir)
|
|
|
|
| 56 |
|
| 57 |
DATASET_NAME = "narrator"
|
| 58 |
EXP_ARCH = "F5TTS_v1_Base"
|
| 59 |
+
WAVS_DIR = Path("/tmp/f5_work/wavs")
|
| 60 |
|
| 61 |
|
| 62 |
def _lib_root() -> Path:
|
|
|
|
| 88 |
tar.extractall("/tmp/", filter="data")
|
| 89 |
print(f"Extracted -> {lj_root}")
|
| 90 |
|
| 91 |
+
WAVS_DIR.mkdir(parents=True, exist_ok=True)
|
| 92 |
+
|
| 93 |
+
# F5-TTS CustomDataset.__getitem__ accesses row["audio_path"] (string path) and
|
| 94 |
+
# row["text"]. It loads audio itself (soundfile/torchaudio) — no HF Audio feature,
|
| 95 |
+
# no torchcodec, no FFmpeg dependency. Just store plain string paths + text.
|
| 96 |
+
wav_paths: list[str] = []
|
| 97 |
texts: list[str] = []
|
| 98 |
durations: list[float] = []
|
| 99 |
count = 0
|
|
|
|
| 123 |
import librosa
|
| 124 |
arr = librosa.resample(arr, orig_sr=orig_sr, target_sr=TARGET_SR)
|
| 125 |
|
| 126 |
+
dest = WAVS_DIR / f"{clip_id}.wav"
|
| 127 |
+
sf.write(str(dest), arr, TARGET_SR)
|
| 128 |
+
wav_paths.append(str(dest))
|
| 129 |
texts.append(text)
|
| 130 |
durations.append(len(arr) / TARGET_SR)
|
| 131 |
count += 1
|
|
|
|
| 138 |
raw_dir = token_dir / "raw"
|
| 139 |
raw_dir.mkdir(parents=True, exist_ok=True)
|
| 140 |
|
| 141 |
+
# No Audio feature, no cast_column — just plain string paths and text
|
| 142 |
+
ds = hf_datasets.Dataset.from_dict({"audio_path": wav_paths, "text": texts})
|
| 143 |
ds.save_to_disk(str(raw_dir))
|
| 144 |
print(f"Saved dataset -> {raw_dir}")
|
| 145 |
|
|
|
|
| 214 |
|
| 215 |
|
| 216 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
prepare_data()
|
| 218 |
ckpt_dir = fine_tune()
|
| 219 |
push_model(ckpt_dir)
|