Skip to main content

memo_stt/
lib.rs

1//! # memo-stt
2//!
3//! Plug-and-play speech-to-text for Rust.
4//!
5//! Add local transcription to any app in a few lines, with automatic GPU
6//! acceleration and zero configuration. Avoid expensive API calls.
7//!
8//! ## Quick example
9//!
10//! ```no_run
11//! use memo_stt::SttEngine;
12//!
13//! # fn run(audio_samples: &[i16]) -> Result<(), Box<dyn std::error::Error>> {
14//! let mut engine = SttEngine::new_default(16000)?;
15//! engine.warmup()?;
16//! let text = engine.transcribe(audio_samples)?;
17//! println!("Transcribed: {}", text);
18//! # Ok(())
19//! # }
20//! ```
21//!
22//! On the first call, the default model (`ggml-small.en-q5_1.bin`, ~500 MB) is
23//! downloaded into the platform cache directory. Every subsequent run is
24//! fully offline.
25//!
26//! ## Recommended model
27//!
28//! Use the default `ggml-small.en-q5_1.bin` for almost every use case. It is
29//! the best general-purpose balance of speed, size, and accuracy for English
30//! speech. Only pick a larger distil model if you specifically need higher
31//! accuracy on noisy audio or accented speech.
32//!
33//! ## Features
34//!
35//! - Zero configuration — model is auto-downloaded on first use.
36//! - Automatic GPU acceleration where supported (Metal on macOS, CUDA on
37//!   Linux/Windows when available); clean CPU fallback otherwise.
38//! - Three-method API: [`SttEngine::new_default`], [`SttEngine::warmup`],
39//!   [`SttEngine::transcribe`].
40//! - Fully local — audio never leaves the machine.
41//! - Cross-platform: macOS, Linux, Windows.
42//!
43//! ## Installation
44//!
45//! ```toml
46//! [dependencies]
47//! memo-stt = "0.1"
48//! ```
49//!
50//! ## Audio format
51//!
52//! `memo-stt` expects 16-bit signed PCM mono samples (`&[i16]`). The input
53//! sample rate is whatever you declare to [`SttEngine::new`] /
54//! [`SttEngine::new_default`]; samples are resampled to 16 kHz internally.
55//!
56//! ## Standalone binary
57//!
58//! A CLI with hotkey, microphone, and BLE-device support is available behind
59//! the `binary` feature:
60//!
61//! ```bash
62//! cargo install memo-stt --features binary
63//! ```
64
65pub mod engine;
66pub mod model;
67
68pub use engine::SttEngine;
69pub use model::{default_model_path, ensure_model};
70
71/// Default model name (`small.en` Q5_1).
72///
73/// This is the recommended general-purpose model and is downloaded
74/// automatically on first use.
75pub const DEFAULT_MODEL: &str = "ggml-small.en-q5_1.bin";
76
77/// Error type used throughout the crate.
78#[derive(Debug)]
79pub struct Error(pub String);
80
81impl std::fmt::Display for Error {
82    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83        write!(f, "{}", self.0)
84    }
85}
86
87impl std::error::Error for Error {}
88
89/// Convenience `Result` alias used throughout the crate.
90pub type Result<T> = std::result::Result<T, Error>;