sub200 / download_models.py
Revrse's picture
Upload 5 files
7875858 verified
Raw History Blame Contribute Delete
1.72 kB
#!/usr/bin/env python3
"""
Download Piper TTS models if not present
This script can be run during Docker build or at startup
"""
import os
import urllib.request
import json
def download_piper_model():
"""Download Piper model if not present"""
models_dir = "models"
os.makedirs(models_dir, exist_ok=True)
model_name = "en_US-lessac-low"
model_file = f"{model_name}.onnx"
config_file = f"{model_name}.onnx.json"
model_path = os.path.join(models_dir, model_file)
config_path = os.path.join(models_dir, config_file)
# Check if model already exists
if os.path.exists(model_path) and os.path.exists(config_path):
print(f"Model {model_name} already exists, skipping download")
return
print(f"Downloading Piper model: {model_name}")
# Hugging Face model repository
base_url = "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US"
try:
# Download model file
if not os.path.exists(model_path):
print(f"Downloading {model_file}...")
url = f"{base_url}/{model_file}"
urllib.request.urlretrieve(url, model_path)
print(f"Downloaded {model_file}")
# Download config file
if not os.path.exists(config_path):
print(f"Downloading {config_file}...")
url = f"{base_url}/{config_file}"
urllib.request.urlretrieve(url, config_path)
print(f"Downloaded {config_file}")
except Exception as e:
print(f"Error downloading model: {e}")
print("Model download failed, but app will continue with other engines")
if __name__ == "__main__":
download_piper_model()