Hexa06 commited on
Commit
7e8b0b3
·
1 Parent(s): 8fd6591

Use Kokoro automatic model download instead of manual URLs

Browse files
Files changed (1) hide show
  1. app.py +11 -30
app.py CHANGED
@@ -63,36 +63,17 @@ app = FastAPI(title="Kokoro TTS API - Professional & Fast")
63
  def startup():
64
  global kokoro
65
  if kokoro is None:
66
- import urllib.request
67
- import os
68
-
69
- print("📥 Downloading Kokoro TTS model files...")
70
-
71
- # Create directories
72
- os.makedirs("models", exist_ok=True)
73
- os.makedirs("voices", exist_ok=True)
74
-
75
- # Download model file if not exists
76
- model_path = "models/kokoro-v0_19.onnx"
77
- if not os.path.exists(model_path):
78
- print("Downloading ONNX model...")
79
- urllib.request.urlretrieve(
80
- "https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files-v0.19/kokoro-v0_19.onnx",
81
- model_path
82
- )
83
-
84
- # Download voices file if not exists
85
- voices_path = "voices/voices.bin"
86
- if not os.path.exists(voices_path):
87
- print("Downloading voices...")
88
- urllib.request.urlretrieve(
89
- "https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files-v1.0/voices-v1.0.bin",
90
- voices_path
91
- )
92
-
93
- print("✅ Model files downloaded!")
94
- kokoro = Kokoro(model_path, "voices")
95
- print("✅ Kokoro TTS loaded!")
96
 
97
  init_admin()
98
 
 
63
  def startup():
64
  global kokoro
65
  if kokoro is None:
66
+ print("📥 Initializing Kokoro TTS (will auto-download models)...")
67
+ try:
68
+ # Kokoro will automatically download models to default location
69
+ kokoro = Kokoro()
70
+ print("✅ Kokoro TTS loaded!")
71
+ except Exception as e:
72
+ print(f"⚠️ Error loading Kokoro: {e}")
73
+ print("Trying alternative initialization...")
74
+ # Fallback: specify paths explicitly
75
+ kokoro = Kokoro("kokoro-v0_19", "voices")
76
+ print("✅ Kokoro TTS loaded (fallback)!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  init_admin()
79