4moha commited on
Commit
cf65221
·
verified ·
1 Parent(s): e2a94ff

Add train_narrator_tts.py

Browse files
Files changed (1) hide show
  1. train_narrator_tts.py +26 -0
train_narrator_tts.py CHANGED
@@ -164,7 +164,33 @@ def prepare_data() -> None:
164
  raise FileNotFoundError(f"Cannot find F5-TTS built-in vocab.txt — searched {builtin_vocab}")
165
 
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  def fine_tune() -> Path:
 
168
  env = {**os.environ, "HF_TOKEN": HF_TOKEN}
169
 
170
  cmd = [
 
164
  raise FileNotFoundError(f"Cannot find F5-TTS built-in vocab.txt — searched {builtin_vocab}")
165
 
166
 
167
+ def _patch_torchaudio() -> None:
168
+ """Write sitecustomize.py into the venv so torchaudio.load uses soundfile.
169
+
170
+ torchaudio 2.6+ delegates load() to torchcodec which needs FFmpeg system libs.
171
+ sitecustomize.py runs at Python startup before any module import, so our patch
172
+ replaces torchaudio.load before F5-TTS's dataset.py ever calls it.
173
+ """
174
+ sc = _lib_root() / "site-packages" / "sitecustomize.py"
175
+ sc.write_text(
176
+ "try:\n"
177
+ " import torchaudio, soundfile as _sf, torch as _torch, numpy as _np\n"
178
+ " def _sf_load(uri, frame_offset=0, num_frames=-1, normalize=True,\n"
179
+ " channels_first=True, format=None, backend=None):\n"
180
+ " arr, sr = _sf.read(str(uri), dtype='float32', always_2d=False)\n"
181
+ " if arr.ndim == 1: arr = arr[_np.newaxis, :]\n"
182
+ " elif channels_first: arr = arr.T\n"
183
+ " return _torch.from_numpy(arr.copy()), sr\n"
184
+ " torchaudio.load = _sf_load\n"
185
+ " print('sitecustomize: torchaudio.load patched to use soundfile')\n"
186
+ "except Exception as _e: print(f'sitecustomize patch failed: {_e}')\n",
187
+ encoding="utf-8",
188
+ )
189
+ print(f"Installed torchaudio soundfile patch -> {sc}")
190
+
191
+
192
  def fine_tune() -> Path:
193
+ _patch_torchaudio()
194
  env = {**os.environ, "HF_TOKEN": HF_TOKEN}
195
 
196
  cmd = [