ashishkblink commited on
Commit
7e6b3d7
·
verified ·
1 Parent(s): 45759ab

Upload f5_tts/infer/utils_infer.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. f5_tts/infer/utils_infer.py +21 -0
f5_tts/infer/utils_infer.py CHANGED
@@ -91,6 +91,27 @@ def chunk_text(text, max_chars=135):
91
  # load vocoder
92
  def load_vocoder(vocoder_name="vocos", is_local=False, local_path="", device=device, hf_cache_dir=None):
93
  if vocoder_name == "vocos":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  # vocoder = Vocos.from_pretrained("charactr/vocos-mel-24khz").to(device)
95
  if is_local:
96
  print(f"Load vocos from local path {local_path}")
 
91
  # load vocoder
92
  def load_vocoder(vocoder_name="vocos", is_local=False, local_path="", device=device, hf_cache_dir=None):
93
  if vocoder_name == "vocos":
94
+ # Check if torchcodec is available before loading vocos
95
+ try:
96
+ import torchcodec
97
+ print("✅ torchcodec is available")
98
+ except ImportError:
99
+ print("⚠️ Warning: torchcodec not found. Attempting to install or use alternative...")
100
+ try:
101
+ import subprocess
102
+ import sys
103
+ print("Installing torchcodec...")
104
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "torchcodec", "-q"])
105
+ import torchcodec
106
+ print("✅ torchcodec installed successfully")
107
+ except Exception as e:
108
+ raise ImportError(
109
+ f"torchcodec is required for vocos vocoder but could not be installed.\n"
110
+ f"Error: {e}\n"
111
+ f"Please add 'torchcodec' to requirements.txt and ensure 'ffmpeg' is installed.\n"
112
+ f"For Hugging Face Spaces, add 'ffmpeg' to packages.txt"
113
+ ) from e
114
+
115
  # vocoder = Vocos.from_pretrained("charactr/vocos-mel-24khz").to(device)
116
  if is_local:
117
  print(f"Load vocos from local path {local_path}")