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.
- Blend
Match - The blend found.
- Engine
- Kokoro and Whisper, in process. Cheap to clone; clones share models.
- Engine
Builder - Match
Request - A recording to match, and how hard to try.
- Model
File - A weights file an engine needs, as
Engine::missingreports it. - Model
Info - Segment
- Speak
Request - A text-to-speech request.
- Speaker
Config - Speaker-embedding settings:
Engine::speaker_embeddingandEngine::match_voice. - Speaker
Embedding - 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.
- Transcribe
Request - A speech-to-text request.
- Transcription
- TtsConfig
- Text-to-speech settings.
- Voice
Info - A voice
Engine::speakaccepts, as open-speech’s/v1/audio/voicesdescribes one. - Whisper
Model - 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.
- Audio
Error - Downloads
- Whether loqui may fetch missing weights.
- Error
- Non-exhaustive because
Sttexists only with thewhisperfeature. - Format
- An output format, named as the OpenAI API names it in
response_format. - Kokoro
Variant - Kokoro model files by precision. fp32 is the reference; the smaller ones trade a little quality for memory and speed.
- Match
Progress - How a match is going, for a progress display; returning
Breakfrom the callback cancels it withError::Cancelled. - Model
Kind - Which model a
ModelInfoorModelFileis 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_embeddingdescribes. - MIN_
MATCH_ SECS - The least speech a recording to match must hold.
- SPEAKER_
MODEL_ ID - The id
Engine::modelslists for the speaker-embedding model. - TTS_
MODEL_ ID - The id
/v1/modelslists 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.