Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/sherpaonnx_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ fn parse_model(id: &str, val: &serde_json::Value) -> Option<SherpaModelInfo> {
.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())
Expand Down Expand Up @@ -1652,6 +1657,7 @@ mod tests {
],
sample_rate: 24000,
num_speakers: 2,
quality: String::new(),
url: String::new(),
compression: false,
filesize_mb: 0.0,
Expand Down Expand Up @@ -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"}"#);
Expand Down
4 changes: 4 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading