Files
vosk-datacleaner/vosk/test_files/download_large_persian_model.py
2025-07-31 17:35:08 +03:30

33 lines
1.1 KiB
Python

import os
import requests
import zipfile
MODEL_URL = "https://alphacephei.com/vosk/models/vosk-model-fa-0.42.zip"
MODEL_ZIP = "vosk-model-fa-0.42.zip"
MODEL_DIR = "vosk-model-fa-0.42"
# Download the model zip if not present
if not os.path.exists(MODEL_ZIP):
print(f"Downloading {MODEL_URL} ...")
with requests.get(MODEL_URL, stream=True) as r:
r.raise_for_status()
total = int(r.headers.get('content-length', 0))
with open(MODEL_ZIP, 'wb') as f:
downloaded = 0
for chunk in r.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
downloaded += len(chunk)
print(f"\rDownloaded {downloaded/1024/1024:.2f} MB / {total/1024/1024:.2f} MB", end='', flush=True)
print("\nDownload complete.")
else:
print(f"{MODEL_ZIP} already exists.")
# Extract the model zip if not already extracted
if not os.path.exists(MODEL_DIR):
print(f"Extracting {MODEL_ZIP} ...")
with zipfile.ZipFile(MODEL_ZIP, 'r') as zip_ref:
zip_ref.extractall()
print(f"Extracted to {MODEL_DIR}.")
else:
print(f"{MODEL_DIR} already extracted.")