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

Fix Kokoro model download with correct release URLs

Browse files
Files changed (1) hide show
  1. app.py +31 -11
app.py CHANGED
@@ -63,17 +63,37 @@ app = FastAPI(title="Kokoro TTS API - Professional & Fast")
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
 
 
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 directory for voices
72
+ os.makedirs("voices", exist_ok=True)
73
+
74
+ # Download voices file
75
+ voices_file = "voices/voices.bin"
76
+ if not os.path.exists(voices_file):
77
+ print("Downloading voices.bin...")
78
+ urllib.request.urlretrieve(
79
+ "https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files/voices.bin",
80
+ voices_file
81
+ )
82
+ print("✅ Voices downloaded!")
83
+
84
+ # Download ONNX model
85
+ model_file = "kokoro-v0_19.onnx"
86
+ if not os.path.exists(model_file):
87
+ print("Downloading kokoro-v0_19.onnx...")
88
+ urllib.request.urlretrieve(
89
+ "https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files/kokoro-v0_19.onnx",
90
+ model_file
91
+ )
92
+ print("✅ Model downloaded!")
93
+
94
+ print("🎤 Initializing Kokoro TTS...")
95
+ kokoro = Kokoro(model_file, voices_file)
96
+ print("✅ Kokoro TTS loaded!")
97
 
98
  init_admin()
99