File size: 915 Bytes
68c9c91 8acf70b 3342236 d102cd2 8acf70b 3342236 8acf70b 86e570a 8acf70b 86e570a 8acf70b 86e570a 8acf70b 86e570a d102cd2 8acf70b 86e570a 8acf70b d457454 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import os
import requests
import zipfile
MODEL_URL = "https://alphacephei.com/vosk/models/vosk-model-vn-0.4.zip"
MODEL_DIR = "model"
MODEL_PATH = os.path.join(MODEL_DIR, "vosk-model")
if not os.path.exists(MODEL_PATH):
os.makedirs(MODEL_DIR, exist_ok=True)
zip_path = os.path.join(MODEL_DIR, "model.zip")
print("📥 Đang tải model Vosk...")
response = requests.get(MODEL_URL, stream=True)
with open(zip_path, "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print("📦 Giải nén model...")
with zipfile.ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall(MODEL_DIR)
os.rename(os.path.join(MODEL_DIR, "vosk-model-vn-0.4"), MODEL_PATH)
os.remove(zip_path) # Xóa file zip sau khi giải nén
print("✅ Model đã tải thành công!")
else:
print("✅ Model đã có sẵn, bỏ qua tải về.") |