[本地唤醒模型]:完成KWS模型下载和检查,包含manifest、配置和model-check
This commit is contained in:
@@ -14,8 +14,19 @@ DEFAULT_STT_URL = (
|
||||
"sherpa-onnx-streaming-zipformer-zh-14M-2023-02-23.tar.bz2"
|
||||
)
|
||||
DEFAULT_STT_DIR = "sherpa-onnx-streaming-zipformer-zh-14M-2023-02-23"
|
||||
DEFAULT_KWS_URL = (
|
||||
"https://github.com/k2-fsa/sherpa-onnx/releases/download/kws-models/"
|
||||
"sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01-mobile.tar.bz2"
|
||||
)
|
||||
DEFAULT_KWS_DIR = "sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01-mobile"
|
||||
DEFAULT_KWS_KEYWORDS = "x iǎo j ié x iǎo j ié @小杰小杰\n"
|
||||
|
||||
REQUIRED_MODEL_FILES = (
|
||||
f"wake/{DEFAULT_KWS_DIR}/tokens.txt",
|
||||
f"wake/{DEFAULT_KWS_DIR}/encoder-epoch-12-avg-2-chunk-16-left-64.int8.onnx",
|
||||
f"wake/{DEFAULT_KWS_DIR}/decoder-epoch-12-avg-2-chunk-16-left-64.onnx",
|
||||
f"wake/{DEFAULT_KWS_DIR}/joiner-epoch-12-avg-2-chunk-16-left-64.int8.onnx",
|
||||
"wake/keywords.txt",
|
||||
"vad/silero_vad.onnx",
|
||||
f"stt/{DEFAULT_STT_DIR}/tokens.txt",
|
||||
f"stt/{DEFAULT_STT_DIR}/encoder-epoch-99-avg-1.int8.onnx",
|
||||
@@ -54,10 +65,20 @@ def default_manifest() -> dict[str, Any]:
|
||||
"schema": "owner_voice_pet.speech_models.v1",
|
||||
"sample_rate": 16000,
|
||||
"sources": {
|
||||
"wake": DEFAULT_KWS_URL,
|
||||
"vad": DEFAULT_VAD_URL,
|
||||
"stt": DEFAULT_STT_URL,
|
||||
},
|
||||
"providers": {
|
||||
"wake": {
|
||||
"type": "sherpa-onnx-keyword-spotter",
|
||||
"model_dir": f"wake/{DEFAULT_KWS_DIR}",
|
||||
"tokens": f"wake/{DEFAULT_KWS_DIR}/tokens.txt",
|
||||
"encoder": f"wake/{DEFAULT_KWS_DIR}/encoder-epoch-12-avg-2-chunk-16-left-64.int8.onnx",
|
||||
"decoder": f"wake/{DEFAULT_KWS_DIR}/decoder-epoch-12-avg-2-chunk-16-left-64.onnx",
|
||||
"joiner": f"wake/{DEFAULT_KWS_DIR}/joiner-epoch-12-avg-2-chunk-16-left-64.int8.onnx",
|
||||
"keywords": "wake/keywords.txt",
|
||||
},
|
||||
"vad": {
|
||||
"type": "silero-vad",
|
||||
"path": "vad/silero_vad.onnx",
|
||||
@@ -106,6 +127,23 @@ def vad_model_path(models_dir: str | Path) -> Path:
|
||||
return root / str(path)
|
||||
|
||||
|
||||
def wake_model_paths(models_dir: str | Path) -> dict[str, Path]:
|
||||
root = Path(models_dir)
|
||||
manifest = load_manifest(root)
|
||||
wake = manifest.get("providers", {}).get("wake", {})
|
||||
return {
|
||||
"model_dir": root / str(wake.get("model_dir", f"wake/{DEFAULT_KWS_DIR}")),
|
||||
"tokens": root / str(wake.get("tokens", f"wake/{DEFAULT_KWS_DIR}/tokens.txt")),
|
||||
"encoder": root
|
||||
/ str(wake.get("encoder", f"wake/{DEFAULT_KWS_DIR}/encoder-epoch-12-avg-2-chunk-16-left-64.int8.onnx")),
|
||||
"decoder": root
|
||||
/ str(wake.get("decoder", f"wake/{DEFAULT_KWS_DIR}/decoder-epoch-12-avg-2-chunk-16-left-64.onnx")),
|
||||
"joiner": root
|
||||
/ str(wake.get("joiner", f"wake/{DEFAULT_KWS_DIR}/joiner-epoch-12-avg-2-chunk-16-left-64.int8.onnx")),
|
||||
"keywords": root / str(wake.get("keywords", "wake/keywords.txt")),
|
||||
}
|
||||
|
||||
|
||||
def stt_model_paths(model_path: str | Path) -> dict[str, Path]:
|
||||
root = Path(model_path)
|
||||
if (root / "manifest.json").exists() or (root / "stt").exists():
|
||||
|
||||
Reference in New Issue
Block a user