初始化
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from faster_whisper.utils import download_model
|
||||
|
||||
|
||||
MODEL_SIZE = "small"
|
||||
MODEL_DIR = Path(__file__).resolve().parent.parent / "models" / f"faster-whisper-{MODEL_SIZE}"
|
||||
REQUIRED_FILES = ("config.json", "model.bin", "tokenizer.json", "vocabulary.txt")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
missing = [name for name in REQUIRED_FILES if not (MODEL_DIR / name).is_file()]
|
||||
if not missing:
|
||||
print(f"Whisper model already exists: {MODEL_DIR}")
|
||||
return 0
|
||||
|
||||
MODEL_DIR.mkdir(parents=True, exist_ok=True)
|
||||
print(f"Downloading faster-whisper-{MODEL_SIZE} to {MODEL_DIR} ...")
|
||||
download_model(MODEL_SIZE, output_dir=str(MODEL_DIR))
|
||||
missing = [name for name in REQUIRED_FILES if not (MODEL_DIR / name).is_file()]
|
||||
if missing:
|
||||
raise RuntimeError(f"Whisper model download is incomplete; missing: {', '.join(missing)}")
|
||||
print(f"Whisper model is ready: {MODEL_DIR}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user