LiveKit Agents

Sarvam with LiveKit

Sarvam Bulbul in a LiveKit agent: through our plugin, or through LiveKit's Sarvam plugin with a changed URL.

With our plugin#

Sarvam Bulbul in eleven Indian languages, in Sarvam's own parameter names.

pip install livekit-plugins-tts-cache-router
agent.py
from livekit.plugins import tts_cache_router# The API key comes from TTS_CACHE_ROUTER_API_KEY.tts = tts_cache_router.TTS(    provider=tts_cache_router.Sarvam(        model="bulbul:v3",        speaker="shubh",        language="hi-IN",    ),)

Pass tts to AgentSession(tts=tts). Set TTS_CACHE_ROUTER_API_KEY in the agent’s environment, and store your Sarvam key under Provider keys. The constructor of TTS itself is on the plugin’s page.

tts_cache_router.Sarvam(...)#

modelstrRequired
"bulbul:v3" or "bulbul:v4-flash".
speakerstrRequired
A Sarvam speaker of the model, e.g. "shubh".
languagestrRequired
A Sarvam language code, e.g. "hi-IN".
pacefloatDefault 1.0
Speech speed, 0.5–2.0.
temperaturefloatDefault 0.6
0.01–1.0. Lower is steadier, higher is more expressive.
dict_idstr | NoneDefault None
A Sarvam pronunciation dictionary to apply. After you edit the dictionary, its sentences are synthesized afresh within about a minute.
pitchfloat | Nonebulbul:v4-flash only
-0.5 (deeper) to 0.5 (higher). None: Sarvam's default, 0.
loudnessfloat | Nonebulbul:v4-flash only
0.1–2.5. None: Sarvam's default, 1.0.
enable_preprocessingbool | Nonebulbul:v4-flash only
Normalize numbers and English words in the text before synthesis. None: Sarvam's default, off.
min_buffer_sizeint | NoneDefault None
Characters Sarvam buffers before it starts synthesizing, 30–200. None: the least Sarvam allows.
max_chunk_lengthint | NoneDefault None
The longest text Sarvam synthesizes in one piece, 50–500; it splits longer sentences. None: the most Sarvam allows, so each sentence is synthesized whole.

Every value the router accepts, and the languages per model, are in Models and options.

Changing settings#

Replies that start afterwards use the new settings:

Python
tts.update_options(speaker="priya", pace=1.1, temperature=0.4)

With LiveKit's Sarvam plugin#

Keep livekit-plugins-sarvam and point it at the router: your router API key in place of your Sarvam key, and the router’s address. Nothing else changes.

pip install livekit-plugins-sarvam
agent.py
import osfrom livekit.plugins import sarvamtts = sarvam.TTS(    model="bulbul:v3",    speaker="shubh",    target_language_code="hi-IN",    api_key=os.environ["TTS_CACHE_ROUTER_API_KEY"],    base_url="https://api.ttscacherouter.dev/sarvam/text-to-speech",    ws_url="wss://api.ttscacherouter.dev/sarvam/text-to-speech/ws",)

ws_url carries streaming (Sarvam’s WebSocket; for bulbul:v4-flash the plugin adds /v2 itself, which the router serves too) and base_url carries synthesize() (Sarvam’s REST API). Set both. Every other argument, pitch, loudness and speech_sample_rate included, goes to Sarvam as the plugin sends it.

Requests, responses and errors keep Sarvam’s own shape. The endpoints behind it are described in Sarvam API drop-in.

Which to choose#

Both use your org's cache and your stored provider key, and sound the same.

  • Our plugin reports only the characters Sarvam billed in LiveKit’s TTSMetrics (cache hits count zero), and lets you switch provider with update_options.
  • Sarvam’s plugin is the smallest change to an agent that already uses it. Its metrics count every character, cached or not; the dashboard’s Usage page has the real split.