use sysinfo::System;
pub fn pick_default_model() -> &'static str {
let mut sys = System::new();
sys.refresh_memory();
let bytes = sys.total_memory();
let ram_gb = (bytes / (1024 * 1024 * 1024)) as u32;
let apple_silicon = cfg!(all(target_os = "macos", target_arch = "aarch64"));
pick(ram_gb, apple_silicon)
}
fn pick(ram_gb: u32, apple_silicon: bool) -> &'static str {
if ram_gb < 8 {
"tiny.en"
} else if ram_gb < 16 {
"base.en"
} else if ram_gb < 32 {
"distil-small.en"
} else if apple_silicon {
"large-v3-turbo"
} else {
"distil-small.en"
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn picks_tiny_for_low_ram() {
assert_eq!(pick(4, false), "tiny.en");
assert_eq!(pick(7, true), "tiny.en");
}
#[test]
fn picks_base_for_mid_ram() {
assert_eq!(pick(8, false), "base.en");
assert_eq!(pick(15, true), "base.en");
}
#[test]
fn picks_distil_small_for_16gb() {
assert_eq!(pick(16, false), "distil-small.en");
assert_eq!(pick(31, true), "distil-small.en");
}
#[test]
fn picks_large_turbo_for_apple_silicon_high_ram() {
assert_eq!(pick(32, true), "large-v3-turbo");
assert_eq!(pick(64, true), "large-v3-turbo");
}
#[test]
fn picks_distil_small_for_x86_high_ram() {
assert_eq!(pick(32, false), "distil-small.en");
assert_eq!(pick(128, false), "distil-small.en");
}
#[test]
fn pick_default_model_returns_a_known_catalog_id() {
let id = pick_default_model();
let catalog = crate::transcription::models::Catalog::builtin();
assert!(
catalog.get(id).is_some(),
"auto-pick returned unknown id: {id}"
);
}
}