From 35848105bce854910b668e948bc79eb096af2fb3 Mon Sep 17 00:00:00 2001 From: will wade Date: Sun, 16 Aug 2026 17:54:22 +0000 Subject: [PATCH] feat(sherpaonnx): surface model quality tier from the registry Registry entries carry a quality/variant tier (high/medium/low/x_low, plus variant markers like int8/fp16); parse_model dropped it. Expose SherpaModelInfo.quality so consumers (VoiceGarden-SPD's voice search) can filter by it. Free-form string: 1196 entries say 'unknown' (mostly MMS), the rest carry tier or variant values. --- src/sherpaonnx_engine.rs | 22 ++++++++++++++++++++++ src/types.rs | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/src/sherpaonnx_engine.rs b/src/sherpaonnx_engine.rs index 9ea71fd..37b112a 100644 --- a/src/sherpaonnx_engine.rs +++ b/src/sherpaonnx_engine.rs @@ -277,6 +277,11 @@ fn parse_model(id: &str, val: &serde_json::Value) -> Option { .get("num_speakers") .and_then(serde_json::Value::as_u64) .unwrap_or(1) as u32, + quality: obj + .get("quality") + .and_then(serde_json::Value::as_str) + .unwrap_or("") + .to_string(), url: obj .get("url") .and_then(|v| v.as_str()) @@ -1652,6 +1657,7 @@ mod tests { ], sample_rate: 24000, num_speakers: 2, + quality: String::new(), url: String::new(), compression: false, filesize_mb: 0.0, @@ -1947,6 +1953,22 @@ mod tests { assert!(model.license_url.is_empty()); } + #[test] + fn test_parse_model_surfaces_quality() { + let json = serde_json::json!({ + "name": "test", "url": "https://example.com", "quality": "high" + }); + let model = parse_model("test-quality", &json).unwrap(); + assert_eq!(model.quality, "high"); + } + + #[test] + fn test_parse_model_quality_defaults_empty() { + let json = serde_json::json!({ "name": "test", "url": "https://example.com" }); + let model = parse_model("test-noquality", &json).unwrap(); + assert!(model.quality.is_empty()); + } + #[test] fn test_engine_speak_with_unknown_model_id_errors_with_count() { let engine = SherpaOnnxEngine::new(r#"{"modelId":"not-a-real-model"}"#); diff --git a/src/types.rs b/src/types.rs index bc5099b..a384aab 100644 --- a/src/types.rs +++ b/src/types.rs @@ -270,6 +270,10 @@ pub struct SherpaModelInfo { pub sample_rate: u32, /// Number of speakers (for multi-speaker models). pub num_speakers: u32, + /// Quality/variant tier from the registry (e.g. `"x_low"`, `"low"`, + /// `"medium"`, `"high"`; some entries carry variant markers like + /// `"int8"` or `"fp16"` instead). Empty when the entry omits it. + pub quality: String, /// Download URL for the model archive. pub url: String, /// Whether the archive is compressed.