Use Kokoro automatic model download instead of manual URLs
Browse files
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 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 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 |
|