Skip to main content

Crate loqui

Crate loqui 

Source
Expand description

Local speech for Rust: Kokoro text-to-speech and Whisper speech-to-text.

An Engine runs both models in process. It opens no sockets and listens on nothing; the only network access is fetching model weights, pinned to commit revisions, and that can be switched off with Downloads::Deny. To serve speech to other processes, see the loqui-server crate, which puts an authenticated, explicitly exposed HTTP API in front of an Engine.

use loqui::{Engine, SpeakRequest};

let engine = Engine::builder().build()?;
let speech = engine.speak(&SpeakRequest::new("Hello from loqui."))?;
std::fs::write("hello.wav", &speech.audio)?;

Models load on first use and, if given an idle timeout, unload when unused. Everything is synchronous; call it from spawn_blocking in async code.

Before shipping an embedded engine, read Embedding loqui safely: downloads, cache permissions, limits on untrusted input, and the licensing each feature brings (leave mp3 off in proprietary programs).

Structs§

Blend
A voice to speak in: one or more voice packs whose weights sum to one.
BlendMatch
The blend found.
Engine
Kokoro and Whisper, in process. Cheap to clone; clones share models.
EngineBuilder
MatchRequest
A recording to match, and how hard to try.
ModelFile
A weights file an engine needs, as Engine::missing reports it.
ModelInfo
Segment
SpeakRequest
A text-to-speech request.
SpeakerConfig
Speaker-embedding settings: Engine::speaker_embedding and Engine::match_voice.
SpeakerEmbedding
A voice, as a point in WeSpeaker’s embedding space: a unit vector, compared with SpeakerEmbedding::similarity.
Speech
Encoded speech.
SttConfig
Speech-to-text settings.
TranscribeRequest
A speech-to-text request.
Transcription
TtsConfig
Text-to-speech settings.
VoiceInfo
A voice Engine::speak accepts, as open-speech’s /v1/audio/voices describes one.
WhisperModel
A Whisper model loqui knows by name.

Enums§

Accent
The accent a match speaks with: Kokoro’s American or British G2P, chosen by the first voice in the blend.
AudioError
Downloads
Whether loqui may fetch missing weights.
Error
Non-exhaustive because Stt exists only with the whisper feature.
Format
An output format, named as the OpenAI API names it in response_format.
KokoroVariant
Kokoro model files by precision. fp32 is the reference; the smaller ones trade a little quality for memory and speed.
MatchProgress
How a match is going, for a progress display; returning Break from the callback cancels it with Error::Cancelled.
ModelKind
Which model a ModelInfo or ModelFile is about. Non-exhaustive: loqui may run more kinds of model.
OovFallback
What happens to a word that no lexicon entry, morphology rule or number rule covers: a name, a coinage, a typo.
SttDevice
Where inference runs.
SttError
Task
TtsDevice
Where inference runs.
TtsError
Non-exhaustive so that a new failure need not be a breaking change.

Constants§

MAX_EVALUATIONS
The most blends a match may speak.
MAX_VOICES
The most voices a match may mix.
MIN_EMBED_SECS
The least speech crate::Engine::speaker_embedding describes.
MIN_MATCH_SECS
The least speech a recording to match must hold.
SPEAKER_MODEL_ID
The id Engine::models lists for the speaker-embedding model.
TTS_MODEL_ID
The id /v1/models lists for the Kokoro model.
WHISPER_MODELS
Whisper models loqui knows by name, with each GGML file’s SHA-256 and size from the repository’s LFS records at the pinned revision.

Functions§

default_cache_dir
The default cache: $XDG_CACHE_HOME/loqui, else ~/.cache/loqui.
whisper_model
The Whisper model named name, if loqui knows it.