adk-audio
Audio intelligence and pipeline orchestration for ADK-Rust agents.
Stability: Beta — the local ONNX TTS backends are untested,
MlxTtsProviderdoes not synthesize yet, and MLX Whisper is new. See STABILITY.md.
adk-audio defines traits for text-to-speech (TTS), speech-to-text (STT), music generation,
audio DSP, and voice activity detection (VAD), ships cloud TTS and STT providers, local ONNX,
Candle, and tokenizer-based models, and composes them into pipelines for voice agents,
transcription, and audio processing.
Installation
[]
= "3.0.0"
Or through the umbrella crate:
[]
= { = "3.0.0", = ["audio"] }
audio enables the default tts and stt features. The umbrella's audio-tts, audio-stt,
audio-fx, audio-mlx, and audio-all enable tts, stt, fx, mlx, and all; kokoro,
qwen3-tts, and all-onnx keep their names; and audio-onnx enables onnx with the
whisper-onnx, distil-whisper, moonshine, and chatterbox models.
Feature flags
| Feature | Enables | Key dependencies |
|---|---|---|
tts (default) |
Cloud TTS providers: ElevenLabs, OpenAI, Gemini, Cartesia | reqwest, base64 |
stt (default) |
Cloud STT providers: OpenAI Whisper API, Deepgram, AssemblyAI, Gemini | reqwest, tokio-tungstenite |
muse |
MuseStt: Meta Muse file and realtime transcription |
adk-model (muse-realtime) |
fx |
DSP processors: normalizer, resampler, noise suppressor, compressor, trimmer, pitch shifter | none |
mlx |
On-device Whisper STT on Apple Silicon Metal GPU (MlxSttProvider) and MLX model loading (MlxTtsProvider); needs cmake and Xcode's Metal toolchain on Apple Silicon |
tokenizers, hf-hub, mlx-rs (Apple Silicon) |
onnx |
ONNX Runtime local inference; ort downloads the onnxruntime binary at build time |
ort, tokenizers, hf-hub |
onnx-cuda |
OnnxExecutionProvider::Cuda (implies onnx); downloads the CUDA build of onnxruntime |
ort (cuda) |
onnx-coreml |
OnnxExecutionProvider::CoreMl (implies onnx); links only on Apple targets |
ort (coreml) |
kokoro |
Kokoro-82M ONNX TTS with the espeak-ng phonemizer (implies onnx) |
espeak-rs, ndarray; needs a system espeak-ng |
chatterbox |
Chatterbox ONNX TTS (implies onnx) |
|
whisper-onnx, distil-whisper, moonshine |
ONNX STT backends (imply onnx) |
|
qwen3-tts |
Qwen3-TTS on Candle (0.6B and 1.7B) | qwen_tts, candle-core, hf-hub |
all-onnx |
onnx, kokoro, chatterbox, whisper-onnx, distil-whisper, moonshine, qwen3-tts |
|
livekit |
RealtimeBridge between adk-realtime audio and pipelines |
base64 |
desktop-audio |
Microphone capture, speaker playback, and VAD turn-taking | cpal |
music |
Adds reqwest for MusicProvider implementations |
reqwest |
all |
Every feature except desktop-audio, onnx-cuda, and onnx-coreml |
Core types
AudioFrame and codecs
AudioFrame is the PCM16 little-endian buffer used throughout the crate. encode and decode
convert frames to and from Pcm16 and Wav; Opus, Mp3, Flac, and Ogg are defined but not
implemented — check AudioFormat::supports_encode() and supports_decode().
use ;
Cloud providers
TTS
Every TTS provider implements TtsProvider with synthesize and synthesize_stream.
| Provider | Default model | Environment variable |
|---|---|---|
ElevenLabsTts |
eleven_multilingual_v2 |
ELEVENLABS_API_KEY |
OpenAiTts |
tts-1; hd() selects tts-1-hd |
OPENAI_API_KEY |
GeminiTts |
gemini-3.8-flash-tts |
GEMINI_API_KEY or GOOGLE_API_KEY |
CartesiaTts |
sonic-3.5 |
CARTESIA_API_KEY |
use ;
async
TtsRequest also takes language, pitch, emotion (Neutral, Happy, Sad, Angry,
Whisper, Excited, Calm), and output_format. Each provider also accepts a CloudTtsConfig
with the API key and an optional base URL.
STT
Every STT provider implements SttProvider with transcribe. transcribe_stream yields typed
TranscriptEvents; a provider without streaming support returns AudioError::Stt from it (the
trait's default) rather than an empty stream, and dropping a returned stream stops the provider's
work for it.
| Event | Meaning |
|---|---|
Started { session_id } |
The provider accepted the session |
SpeechStarted { turn_id, offset_ms } |
Speech began |
Partial { turn_id, text } |
The current hypothesis for the turn, in full; replace, do not append |
Final { turn_id, transcript } |
Text the provider will not revise |
SpeechEnded { turn_id, offset_ms } |
Speech stopped |
Speaker { label, offset_ms } |
The speaker changed (diarization) |
Progress { processed_ms } |
Audio processed so far |
Usage { audio_ms } |
The audio the session is billed for |
| Provider | Default model | transcribe_stream |
Environment variable |
|---|---|---|---|
WhisperApiStt |
whisper-1 |
AudioError::Stt (not yet implemented) |
OPENAI_API_KEY |
DeepgramStt |
nova-3, with diarization |
WebSocket streaming: Partial for interim results, Final per finalized segment, SpeechStarted/SpeechEnded from voice activity, Usage from the closing metadata; dropping the stream closes the socket |
DEEPGRAM_API_KEY |
AssemblyAiStt |
asynchronous jobs | AudioError::Stt (not yet implemented) |
ASSEMBLYAI_API_KEY |
MuseStt (muse) |
muse-voice-transcribe-1.0 |
Realtime WebSocket: Partial per cumulative transcript, one Final per turn, SpeechStarted/SpeechEnded, Speaker with diarization, Progress, Usage; the 60-minute session limit ends the stream with model.muse.session_limit |
META_API_KEY or MODEL_API_KEY |
GeminiStt |
gemini-3.8-flash |
AudioError::Stt; use the Gemini Live API through adk-realtime for live audio |
GEMINI_API_KEY or GOOGLE_API_KEY |
use ;
async
use Pin;
use ;
use ;
async
A Transcript carries text, per-Word timestamps and confidence, Speaker diarization, overall
confidence, and language_detected.
Local inference
Models download from Hugging Face Hub into LocalModelRegistry's cache
(<cache dir>/adk-audio/models by default; LocalModelRegistry::new(dir) sets another).
ONNX TTS
Needs the onnx feature.
use ;
async
OnnxTtsProvider::new(OnnxModelConfig, ®istry) loads another model. The provider is generic
over a Preprocessor: TokenizerPreprocessor uses a Hugging Face tokenizer.json, and
KokoroPreprocessor (kokoro feature) runs the espeak-ng phonemizer. Execution providers are
OnnxExecutionProvider::Cpu, Cuda, CoreMl, and DirectMl; auto_detect() picks CoreMl on
macOS and Cpu elsewhere. Cuda needs the onnx-cuda feature and CoreMl needs onnx-coreml.
A provider whose feature is off, and DirectMl, logs a warning and the session runs on the CPU.
ONNX STT
| Backend | Feature | Sizes |
|---|---|---|
SttBackend::Whisper |
whisper-onnx |
WhisperModelSize::{Tiny, Base, Small, Medium, LargeV3Turbo} |
SttBackend::DistilWhisper |
distil-whisper |
DistilWhisperVariant::{DistilSmallEn, DistilMediumEn, DistilLargeV3} |
SttBackend::Moonshine |
moonshine |
MoonshineVariant::{Tiny, Base} |
The example needs the whisper-onnx feature.
use ;
async
MLX
On Apple Silicon (aarch64-apple-darwin), MlxSttProvider runs on-device Whisper speech-to-text on
Metal GPU via mlx-rs: greedy decoding in 30-second windows up to MlxSttConfig::max_duration_secs
(600 s by default), with automatic mono downmixing and 16 kHz resampling on a dedicated worker
thread so the async runtime never blocks. On other targets, --features mlx compiles (load-only)
and MlxSttProvider::transcribe returns AudioError::Stt stating Apple Silicon is required.
- Checkpoints: unquantized safetensors (
weights.safetensorsormodel.safetensors), including the defaultmlx-community/whisper-large-v3-turboandmlx-community/whisper-*-fp16;.npz-only and quantized (-4bit/-8bit) checkpoints returnAudioError::Stt. - Tokenizer: uses
tokenizer.jsonin the model directory when present, otherwise downloads onlytokenizer.jsonfrom the matchingopenai/whisper-*repository based onconfig.jsonn_vocab. - Language:
.encheckpoints (n_vocab < 51865) ignoreSttOptions::language; multilingual checkpoints default to"en"whenlanguageisNone. - Silence: a 30-second window whose RMS level is below about -80 dBFS is skipped and yields no text, so audio that is silent throughout returns an empty transcript.
- Limits: audio longer than
max_duration_secsreturnsAudioError::Stt. The worker reserves buffers for at most 600 s of audio up front; a higher limit grows them with the audio submitted. A request whose caller drops it stops at the next 30-second window. - Streaming and TTS:
MlxSttProvider::transcribe_streamreturnsAudioError::Stt(calltranscribewith buffered audio), andMlxTtsProviderinference is not implemented (synthesizereturnsAudioError::Tts). - Build requirements on Apple Silicon (
--features mlxand--features all):cmakeand Xcode's Metal toolchain. Themlx-sysbuild fetches MLX from GitHub, so it needs network access, and writesmlx.metallib(about 175 MB) under~/.mlx/lib/.
The example needs the mlx feature (and Apple Silicon to run inference).
use ;
async
Qwen3-TTS
Candle-based TTS for 10 languages with predefined speakers. On macOS it runs on Metal when the
build's candle-core has Metal support, and on the CPU otherwise; elsewhere on the CPU. Needs the
qwen3-tts feature.
use ;
async
Variants: Small (0.6B) and Large (1.7B). Speakers: vivian, serena, dylan, eric,
ryan, aiden (English), uncle_fu (Chinese), ono_anna (Japanese), sohee (Korean).
Chatterbox
ChatterboxTtsProvider::load(ChatterboxConfig::default()) loads
onnx-community/chatterbox-ONNX; ChatterboxVariant selects Fp32, Fp16, Q4, or Q4F16.
DSP processors
Behind the fx feature; each implements AudioProcessor.
| Processor | Description |
|---|---|
LoudnessNormalizer |
EBU R128 loudness normalization, -23 LUFS by default (with_target) |
Resampler |
Sample rate conversion |
NoiseSuppressor |
Noise reduction below a sample threshold |
DynamicRangeCompressor |
Dynamic range compression |
SilenceTrimmer |
Leading and trailing silence removal |
PitchShifter |
Pitch adjustment by a factor |
FxChain runs processors in series:
use ;
async
Mixer
use ;
Pipelines
AudioPipelineBuilder composes providers, processors, and an agent. Each build_* method returns
a PipelineHandle with input_tx and output_rx channels, shared metrics, and shutdown().
| Builder method | Flow | Required components |
|---|---|---|
build_tts() |
Text → TTS → audio | tts |
build_stt() |
Audio → STT → transcript | stt |
build_voice_agent() |
Audio → VAD → STT → agent → TTS → audio | tts, stt, vad, agent |
build_transform() |
Audio → FxChain → audio |
pre_fx (optional) |
build_music() |
Text → music provider → audio | music |
use Arc;
use ;
async
PipelineMetrics records tts_latency_ms, stt_latency_ms, llm_latency_ms, total_audio_ms,
and vad_speech_ratio. pipeline::presets has ivr_pipeline(tts, stt, vad, agent),
podcast_pipeline(tts), transcription_pipeline(stt), and enhance_pipeline().
SentenceChunker
SentenceChunker buffers LLM tokens and emits complete sentences at ., !, ?, ;, and
newline boundaries, which shortens the time to the first audio in a voice agent:
use SentenceChunker;
Agent tools
Four adk_core::Tool implementations:
| Tool | Description | Arguments |
|---|---|---|
SpeakTool |
Synthesize text to speech | {text, voice?, emotion?} |
TranscribeTool |
Transcribe audio to text | {audio_data (base64), sample_rate?, language?} |
ApplyFxTool |
Apply a named FX chain | {audio_data (base64), chain, sample_rate?} |
GenerateMusicTool |
Generate music from a prompt | {prompt, duration_secs, genre?} |
use Arc;
use ;
use Tool;
Metering
SttProvider::billing and TtsProvider::billing name the vendor and model a cloud provider's
calls are billed under; local models return None. TranscribeTool and SpeakTool meter each
billed call against the run the tool call belongs to, in audioMillis and characters, through
adk_core::meter_usage. The bundled cloud providers carry no per-unit price, so a run budget's
cost cap or a spend-ledger limit refuses their calls before they are sent; see
Calls billed in units.
VAD and music
VadProcessor (is_speech, segment) and MusicProvider are traits; the crate ships no
implementation of either, so the voice agent pipeline and GenerateMusicTool take one from the
application.
Desktop audio
Behind desktop-audio: AudioCapture records from an input device, AudioPlayback plays frames
on an output device, and VadTurnManager turns a VadProcessor's decisions into
VoiceActivityEvents. AudioCapture::list_input_devices() and
AudioPlayback::list_output_devices() enumerate devices. On Linux the build needs ALSA headers
(libasound2-dev).
Realtime bridge
Behind livekit, RealtimeBridge converts between adk-realtime base64 PCM16 audio streams and
pipeline inputs and outputs:
use Pin;
use ;
use Stream;
Errors
Operations return AudioResult<T>, an alias for Result<T, AudioError>:
| Variant | Description |
|---|---|
Tts { provider, message } |
TTS provider error |
Stt { provider, message } |
STT provider error |
Music(String) |
Music generation error |
Fx(String) |
Audio processing error |
PipelineClosed(String) |
Pipeline misconfigured or shut down |
Vad(String) |
Voice activity detection error |
Codec(String) |
Encode or decode error |
ModelDownload { model_id, message } |
Model download or registry error |
Io(std::io::Error) |
I/O error |
Network(reqwest::Error) |
HTTP error (tts, stt, or music) |
Device(String) |
Audio device error (desktop-audio) |
Related crates
- adk-rust — umbrella crate
- adk-core —
ToolandAgenttraits - adk-realtime — real-time audio and video streaming
License
Apache-2.0