A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.
Rust
//! O Whisper local da Ilha (02/12/2026, build-63: a transcrição da OpenAI acabava em "You have no credits remaining").
//! O whisper.cpp oficial (GitHub ggml-org/whisper.cpp, release fixa REL) e os modelos ggml oficiais (Hugging Face
//! ggerganov/whisper.cpp, revisão fixa HF_REV), baixados só quando a pessoa pede, para %LOCALAPPDATA%\WacOS\whisper.
//! Tudo conferido pelo SHA-256 publicado (o do GitHub no "digest" do arquivo da release; o do Hugging Face no LFS) antes
//! de valer; download interrompido continua de onde parou. Com placa da NVIDIA vai o motor CUDA (e o de CPU junto, de
//! reserva, 9 MB); sem ela, só o de CPU. O Shell (voz_ouvir.rs) abre o whisper-server.exe com o modelo e manda o áudio.
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicU8, Ordering};
use std::sync::Mutex;
pub const REL: &str = "b5907";
pub const HF_REV: &str = "5359861c739e955e79d9a303bcbc70fb988958b1";
/// (id, arquivo, bytes, sha256, nome)
pub struct Modelo {
pub id: &'static str,
pub arquivo: &'static str,
pub bytes: u64,
pub sha256: &'static str,
pub nome: &'static str,
}
pub const MODELOS: [Modelo; 3] = [
Modelo { id: "turbo", arquivo: "ggml-large-v3-turbo.bin", bytes: 1_624_555_275, sha256: "1fc70f774d38eb169993ac391eea357ef47c88757ef72ee5943879b7e8e2bc69", nome: "Turbo (large-v3-turbo)" },
Modelo { id: "turbo-q5", arquivo: "ggml-large-v3-turbo-q5_0.bin", bytes: 574_041_195, sha256: "394221709cd5ad1f40c46e6031ca61bce88931e6e088c188294c6d5a55ffa7e2", nome: "Turbo compacto (large-v3-turbo q5)" },
Modelo { id: "base", arquivo: "ggml-base.bin", bytes: 147_951_465, sha256: "60ed5bc3dd14eea856493d334349b405782ddcaf0028d4b5df4088345fba2efe", nome: "Base (PCs fracos)" },
];
/// (id, arquivo da release, bytes, sha256)
pub struct Motor {
pub id: &'static str,
pub zip: &'static str,
pub bytes: u64,
pub sha256: &'static str,
}
pub const MOTOR_CUDA: Motor = Motor { id: "cuda", zip: "whisper-bin-win-cuda-12.4.0-x64.zip", bytes: 735_571_214, sha256: "34f872ce724ca1ff0a4afca481853e5ee74250f8cb22153e499f953562846039" };
pub const MOTOR_CPU: Motor = Motor { id: "cpu", zip: "whisper-bin-x64.zip", bytes: 9_168_428, sha256: "ecca07b277d943e9b9f4712856a144b857271a6b333104e511e1988e80db582b" };
pub fn pasta() -> PathBuf {
PathBuf::from(std::env::var("LOCALAPPDATA").unwrap_or_default()).join("WacOS").join("whisper")
}
/// há uma placa da NVIDIA com o driver (o nvcuda.dll do driver)
pub fn tem_nvidia() -> bool {
PathBuf::from(std::env::var("SystemRoot").unwrap_or_else(|_| "C:\\Windows".into())).join("System32").join("nvcuda.dll").is_file()
}
/// o modelo padrão: o Turbo inteiro com a NVIDIA; o compacto sem ela
pub fn modelo_padrao() -> &'static str {
if tem_nvidia() { "turbo" } else { "turbo-q5" }
}
pub fn modelo(id: &str) -> &'static Modelo {
MODELOS.iter().find(|m| m.id == id).unwrap_or(&MODELOS[0])
}
pub fn caminho_modelo(id: &str) -> PathBuf {
pasta().join(modelo(id).arquivo)
}
pub fn modelo_instalado(id: &str) -> bool {
std::fs::metadata(caminho_modelo(id)).map(|m| m.len() == modelo(id).bytes).unwrap_or(false)
}
/// o whisper-server.exe de um motor
pub fn servidor(m: &Motor) -> PathBuf {
pasta().join(format!("motor-{}", m.id)).join("Release").join("whisper-server.exe")
}
/// os motores instalados, na ordem de tentar (CUDA primeiro)
pub fn motores() -> Vec<(&'static str, PathBuf)> {
[&MOTOR_CUDA, &MOTOR_CPU].iter().map(|m| (m.id, servidor(m))).filter(|x| x.1.is_file()).collect()
}
/// pronto para transcrever: um motor e o modelo
pub fn pronto(modelo_id: &str) -> bool {
!motores().is_empty() && modelo_instalado(modelo_id)
}
/// quanto falta baixar (motor + modelo), em bytes
pub fn falta_baixar(modelo_id: &str) -> u64 {
let mut n = 0;
if !servidor(&MOTOR_CPU).is_file() {
n += MOTOR_CPU.bytes;
}
if tem_nvidia() && !servidor(&MOTOR_CUDA).is_file() {
n += MOTOR_CUDA.bytes;
}
if !modelo_instalado(modelo_id) {
n += modelo(modelo_id).bytes;
}
n
}
// ---- o download (um por vez)
/// 0 parado, 1 baixando, 2 conferindo, 3 erro
pub static FASE: AtomicU8 = AtomicU8::new(0);
pub static FEITO: AtomicU64 = AtomicU64::new(0);
pub static TOTAL: AtomicU64 = AtomicU64::new(0);
pub static CANCELA: AtomicBool = AtomicBool::new(false);
pub static ERRO: Mutex<String> = Mutex::new(String::new());
fn sistema(exe: &str) -> String {
format!("{}\\System32\\{exe}", std::env::var("SystemRoot").unwrap_or_else(|_| "C:\\Windows".into()))
}
/// o SHA-256 de um arquivo pelo certutil do Windows, em minúsculas
pub fn sha256(p: &std::path::Path) -> String {
use std::os::windows::process::CommandExt;
let Ok(o) = std::process::Command::new(sistema("certutil.exe")).args(["-hashfile", &p.to_string_lossy(), "SHA256"]).creation_flags(0x0800_0000).output() else { return String::new() };
String::from_utf8_lossy(&o.stdout).lines().nth(1).unwrap_or("").chars().filter(|c| c.is_ascii_hexdigit()).collect::<String>().to_lowercase()
}
/// baixa com o curl (continua de onde parou), somando `base` no progresso; true = chegou com o tamanho certo
fn curl(url: &str, dest: &std::path::Path, bytes: u64, base: u64) -> bool {
use std::os::windows::process::CommandExt;
let Ok(mut ch) = std::process::Command::new(sistema("curl.exe"))
.args(["-L", "-f", "-s", "--retry", "3", "-C", "-", "-o", &dest.to_string_lossy(), url])
.creation_flags(0x0800_0000)
.spawn()
else {
return false;
};
loop {
let n = std::fs::metadata(dest).map(|m| m.len()).unwrap_or(0);
FEITO.store(base + n.min(bytes), Ordering::Relaxed);
if CANCELA.load(Ordering::SeqCst) {
let _ = ch.kill();
let _ = ch.wait();
return false;
}
match ch.try_wait() {
Ok(Some(_)) => break,
Ok(None) => std::thread::sleep(std::time::Duration::from_millis(200)),
Err(_) => return false,
}
}
std::fs::metadata(dest).map(|m| m.len()).unwrap_or(0) == bytes
}
fn falha(e: &str) {
*ERRO.lock().unwrap() = e.to_string();
FASE.store(if CANCELA.load(Ordering::SeqCst) { 0 } else { 3 }, Ordering::SeqCst);
}
/// baixa o que falta para o modelo `modelo_id` (motor CPU, motor CUDA com NVIDIA, modelo); `avisa` roda no fim
pub fn baixa(modelo_id: &str, avisa: impl Fn() + Send + 'static) {
if matches!(FASE.load(Ordering::SeqCst), 1 | 2) {
return;
}
CANCELA.store(false, Ordering::SeqCst);
ERRO.lock().unwrap().clear();
let id = modelo_id.to_string();
FEITO.store(0, Ordering::Relaxed);
TOTAL.store(falta_baixar(&id), Ordering::Relaxed);
FASE.store(1, Ordering::SeqCst);
std::thread::spawn(move || {
let d = pasta();
let _ = std::fs::create_dir_all(&d);
let mut base = 0u64;
let mut motores: Vec<&Motor> = vec![&MOTOR_CPU];
if tem_nvidia() {
motores.push(&MOTOR_CUDA);
}
for m in motores {
if servidor(m).is_file() {
continue;
}
let zip = d.join(format!("{}.baixando", m.zip));
let url = format!("https://github.com/ggml-org/whisper.cpp/releases/download/{REL}/{}", m.zip);
if !curl(&url, &zip, m.bytes, base) {
return { falha("O motor do Whisper não baixou"); avisa() };
}
FASE.store(2, Ordering::SeqCst);
if sha256(&zip) != m.sha256 {
let _ = std::fs::remove_file(&zip);
return { falha("O motor do Whisper não conferiu (SHA-256)"); avisa() };
}
let alvo = d.join(format!("motor-{}", m.id));
let _ = std::fs::remove_dir_all(&alvo);
let _ = std::fs::create_dir_all(&alvo);
let ok = {
use std::os::windows::process::CommandExt;
std::process::Command::new(sistema("tar.exe")).args(["-xf", &zip.to_string_lossy(), "-C", &alvo.to_string_lossy()]).creation_flags(0x0800_0000).status().is_ok_and(|s| s.success())
};
let _ = std::fs::remove_file(&zip);
if !ok || !servidor(m).is_file() {
return { falha("O motor do Whisper não abriu"); avisa() };
}
FASE.store(1, Ordering::SeqCst);
base += m.bytes;
}
if !modelo_instalado(&id) {
let md = modelo(&id);
let tmp = d.join(format!("{}.baixando", md.arquivo));
let url = format!("https://huggingface.co/ggerganov/whisper.cpp/resolve/{HF_REV}/{}", md.arquivo);
if !curl(&url, &tmp, md.bytes, base) {
return { falha("O modelo do Whisper não baixou; tente de novo (continua de onde parou)"); avisa() };
}
FASE.store(2, Ordering::SeqCst);
if sha256(&tmp) != md.sha256 {
let _ = std::fs::remove_file(&tmp);
return { falha("O modelo do Whisper não conferiu (SHA-256)"); avisa() };
}
let fim = d.join(md.arquivo);
let _ = std::fs::remove_file(&fim);
if std::fs::rename(&tmp, &fim).is_err() {
return { falha("Não deu para gravar o modelo do Whisper"); avisa() };
}
}
FASE.store(0, Ordering::SeqCst);
avisa();
});
}
/// apaga um modelo baixado (o motor fica)
pub fn remove_modelo(id: &str) {
let _ = std::fs::remove_file(caminho_modelo(id));
}