Skip to main content
livekit-plugins-slng adds speech to text (STT) and text to speech (TTS) adapters for LiveKit Agents. Pass a model identifier and the plugin builds the bridge endpoint itself, so every streaming model on the platform works with the same code. This page is the plugin reference. For a walkthrough that sets up your models in the dashboard and applies the change, see the LiveKit integration guide.
The plugin is realtime WebSocket only, so HTTP-only models (such as batch STT) are not available through it. This page documents version 1.6.7 and later; upgrading from 1.6.6 or earlier? Read Migrating from earlier versions first.

Prerequisites

Install

Quickstart

The plugin reads your key from SLNG_API_KEY, or pass it with api_key. Create an STT and a TTS instance and hand them to your agent session:
Language codes are sent verbatim. Use the exact value the model expects, for example BCP-47 hi-IN for Sarvam Bulbul, not hi.
agent.py

Model identifiers

Models follow provider/model:variant. A bare identifier is the external passthrough route; prefix with slng/ for an SLNG-hosted instance.
See the model catalog for the full list.

STT reference

slng.STT streams speech to text over WebSocket. Provide either model or connections; there is no default. Only 16-bit PCM (pcm_s16le) input is supported, and batch recognize() is not available, so use stream().
Any extra keyword argument is forwarded to the bridge init payload; the bridge applies the options the model’s catalog declares and ignores the rest (for example Deepgram’s endpointing and smart_format).

TTS reference

slng.TTS streams text to speech over WebSocket. voice is required and passed verbatim as the provider’s voice ID. Use tts.stream() for voice agents and tts.synthesize(text) for one-shot previews. Change voice, language, and speed at runtime with tts.update_options(...).
Extra keyword arguments are forwarded per the model’s contract (for example Rime Arcana speakingStyle or Cartesia Sonic emotion). Pass pronunciation={"mode": "rewrite", "name": "my-dictionary"} to apply a pronunciation dictionary. Pick a voice that matches your model from the text to speech catalog.

Text chunking

text_chunking="auto" (the default) batches words into phrases, flushing at punctuation or phrase_max_chars. This avoids the choppy audio that word-by-word streaming causes on some providers. Set "word" only if you need per-word forwarding.

Warm standby connections

By default each turn opens a fresh connection, adding setup time to its first audio. With warm_standby_enabled=True, the plugin pre-opens the next connection while the current turn plays, so time to first audio drops to roughly the provider’s generation time.
The standby is a single connection per instance and counts toward your concurrency limit while it waits. If it expires during a long silence, the plugin reconnects at regular latency with no error. Where a provider exposes an inactivity option, pass it as a model option to keep the standby alive through pauses.

Failover

Pass connections=[...], an ordered list of candidates (model identifiers, bridge endpoint URLs, or STTConnectionConfig / TTSConnectionConfig objects). When connections supplies the full list, model is not needed.
  • Each candidate gets APIConnectOptions.max_retry attempts before the next is tried. Deterministic 4xx errors advance immediately; HTTP 413 is terminal.
  • STT fails over at safe stream boundaries and replays buffered audio, so no speech is lost. TTS switches only before its first audio, and all TTS candidates must share a sample rate and channel count.
  • After fallback_recovery_cooldown_s (60s default), the primary is retried on the next request. A single candidate reconnects and replays on a transient drop instead of ending the stream.
STTConnectionConfig and TTSConnectionConfig keep endpoint-specific headers, init payloads, and voices together; simple candidates inherit the global settings.

Bring your own key (BYOK)

Pass provider_api_key to use your own provider credential. The plugin sends it as the X-Slng-Provider-Key header on external (passthrough) routes only. See Bring your own key.

Region routing

Route to a sovereign hub by pointing base_url at a regional gateway host, for example eu.api.slng.ai or us.api.slng.ai. Data stays in-jurisdiction and every hub runs the full stack. See the regions map for the available hosts.

Plugin events

Subscribe to slng_event for typed events covering gateway session identifiers (gateway.session) and failover activity (fallback.attempt_failed, fallback.switch_succeeded, fallback.primary_recovered, fallback.exhausted).
external_agent_id and external_session_id (max 128 characters) attach your own identifiers to usage events as the X-SLNG-Agent-Id and X-SLNG-Session-Id headers, so you can correlate gateway usage with your analytics.

Migrating from earlier versions

Version 1.6.7 is a breaking rewrite:
  • All traffic goes through the bridge. model_endpoint and model_endpoints were removed; pass a model or connections instead.
  • STT has no default model, and recognize() (HTTP batch) is gone; use stream() with pcm_s16le input.
  • TTS voice is required and passed verbatim.
  • Language codes are no longer normalized client-side.
  • api_token is deprecated; use api_key.
  • Provider-specific defaults were removed; configure candidates via connections.

Next steps