loqui_speaker/lib.rs
1//! Speaker embeddings: a fixed-length vector that says what a voice sounds
2//! like, independent of what it says.
3//!
4//! Two pieces, both small: [`fbank`], Kaldi's log mel filterbank in pure Rust
5//! (the features WeSpeaker's models are trained on), and [`SpeakerEncoder`],
6//! the network on ONNX Runtime. Two recordings of one voice land close
7//! together, measured by [`cosine`]; that is what lets an application find
8//! the blend of Kokoro voices closest to a recording.
9//!
10//! **An embedding is a similarity, never an identity.** It says how alike two
11//! voices sound, which a recording, a synthesizer or an impression can all
12//! influence; it is not evidence of who is speaking and must not be used to
13//! authenticate anyone.
14//!
15//! Weights are not bundled: the `loqui` facade downloads the pinned model.
16//! WeSpeaker's VoxCeleb models are licensed CC-BY-4.0, the licence of the
17//! VoxCeleb dataset; see `NOTICE`.
18
19pub mod encoder;
20pub mod fbank;
21
22pub use encoder::{MIN_FRAMES, SpeakerEncoder, cosine, normalize};
23pub use fbank::{Fbank, Features, MEL_BINS, SAMPLE_RATE};
24
25/// Why an embedding could not be computed.
26#[derive(Debug, thiserror::Error)]
27#[non_exhaustive]
28pub enum Error {
29 /// The model would not load, or would not run.
30 #[error("speaker model: {0}")]
31 Model(String),
32 /// Too little audio to say anything about a voice.
33 #[error("{secs:.1} s of audio is too short to describe a voice; {min_secs:.1} s is the least")]
34 TooShort { secs: f32, min_secs: f32 },
35}