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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Model download and cache management.
//!
//! Downloads STT/TTS/VAD models, verifies SHA-256 integrity,
//! and caches them in the local filesystem.
use std::path::PathBuf;
/// Manages voice model downloads, caching, and integrity verification.
pub struct ModelDownloadManager {
cache_dir: PathBuf,
}
/// Information about a downloadable model.
#[derive(Debug, Clone)]
pub struct ModelInfo {
/// Model identifier (e.g., "sherpa-onnx-streaming-zipformer-en-20M").
pub id: String,
/// Download URL.
pub url: String,
/// Expected SHA-256 hash of the downloaded file.
pub sha256: String,
/// File size in bytes (for progress reporting).
pub size_bytes: u64,
}
impl ModelDownloadManager {
/// Create a new manager with the given cache directory.
pub fn new(cache_dir: PathBuf) -> Self {
Self { cache_dir }
}
/// Get the cache directory path.
pub fn cache_dir(&self) -> &PathBuf {
&self.cache_dir
}
/// Check if a model is already cached and valid.
pub fn is_cached(&self, model: &ModelInfo) -> bool {
let model_path = self.cache_dir.join(&model.id);
model_path.exists()
}
/// Get the local path where a model would be cached.
pub fn model_path(&self, model_id: &str) -> PathBuf {
self.cache_dir.join(model_id)
}
/// List available STT models.
pub fn available_stt_models() -> Vec<ModelInfo> {
vec![
ModelInfo {
id: "sherpa-onnx-streaming-zipformer-en-20M".into(),
url: "https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-zipformer-en-20M.tar.bz2".into(),
sha256: "PLACEHOLDER_SHA256_STT".into(),
size_bytes: 20_000_000,
},
]
}
/// List available TTS models.
pub fn available_tts_models() -> Vec<ModelInfo> {
vec![
ModelInfo {
id: "vits-piper-en_US-amy-medium".into(),
url: "https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-en_US-amy-medium.tar.bz2".into(),
sha256: "PLACEHOLDER_SHA256_TTS".into(),
size_bytes: 40_000_000,
},
]
}
/// List available VAD models.
pub fn available_vad_models() -> Vec<ModelInfo> {
vec![
ModelInfo {
id: "silero-vad-v5".into(),
url: "https://github.com/snakers4/silero-vad/raw/master/files/silero_vad.onnx".into(),
sha256: "PLACEHOLDER_SHA256_VAD".into(),
size_bytes: 2_000_000,
},
]
}
}