Get started

Overview

How the router serves each sentence from your cache or your provider, what it caches, and the ways to connect.

View as Markdown

How it works#

tts-cache-router sits between your voice agent and your text-to-speech provider. Every sentence your agent has said before plays from a cache; the rest go to the provider with your own key.

Your agent sends text, all at once or streamed from an LLM. The router splits it into sentences as it arrives. A sentence your org has synthesized before, with the same voice and settings, is replayed from your org’s cache. Any other sentence goes to your provider (Vaakini, Sarvam, Raya, ElevenLabs, OpenAI, Deepgram, xAI, Soniox, Smallest AI, Cartesia, Gemini or 60db) with the provider key you stored, or to Maya Open-Source, which we run on our own GPU with no key, streams back as the provider produces it, and is cached once the provider finishes it. You hear the sentences in order, as one reply.

One reply from your agent, split into sentences
  1. 0

    Thanks for calling City Hospital.

    cache

    Said before: replayed from your cache. The provider isn't called.

  2. 1

    Your appointment with Dr. Sharma is on Thursday at ten.

    provider

    New: synthesized by your provider with your key, streamed to you as it arrives, then cached.

  3. 2

    Is there anything else I can help you with?

    cache

    Said before: replayed from your cache.

Each repeat served from the cache is a sentence your provider doesn’t synthesize or bill. The dashboard’s Usage page shows what it saved.

Same output as the provider#

Calling a provider through the router sounds the same as calling it directly:

  • Each sentence reaches the provider verbatim, with your exact model, voice, language, speed, sample rate, format and options. The only change to the text is collapsing runs of whitespace.
  • A cache hit replays a real provider take: audio the provider made for the same sentence and settings. (Two identical direct calls aren’t byte-identical either; each is a new take.)
  • Audio is never spliced, re-encoded or altered. Every format comes from the provider; a format the router can’t serve without re-encoding is refused.
  • A partial clip is never cached. A sentence is cached only once the provider has completed it.

Sentence boundaries come from the splitter each provider’s LiveKit plugin uses: LiveKit’s BlingFire tokenizer for ElevenLabs, OpenAI, Deepgram, xAI, Soniox, Smallest AI, Cartesia and Gemini, plus a sentence end at every danda (।, ॥), so Hindi, Bengali, Punjabi and other replies written with it stream sentence by sentence. For Maya Open-Source, Vaakini, Sarvam, Raya and 60db, the router’s own splitter, built on Raya’s, also ends sentences at the danda and doesn’t split inside common abbreviations (Dr., a.m.), decimals or URLs.

Both also end a reply’s first piece after a comma followed by a space (1,250 is never cut), so the first audio of a reply waits only for its first clause, not its first sentence; after it, pieces end at sentence ends. Unlike LiveKit’s tokenizer, the router sends even a short sentence or clause on its own: a reply opening Sure! starts playing as soon as that word is written.

What is cached#

One entry per sentence: the provider's audio, for your org, keyed by the exact request that produced it.

When a sentence matches#

A sentence plays from the cache when all of these match an earlier, completed one:

  • your org (orgs never share audio; every API key in an org shares its cache);
  • the provider, model, voice, language, speed, sample rate, format and every option;
  • the text, after whitespace is collapsed. Case and punctuation count.

Leaving an option out and sending its default value match. The LiveKit plugin, /v1/stream and /v1/audio/speech share entries for the same settings. Vaakini’s, Raya’s, Sarvam’s, ElevenLabs’, OpenAI’s, Deepgram’s, xAI’s, Soniox’s, Smallest AI’s, Cartesia’s and Gemini’s HTTP API drop-ins split each request into sentences and share them too where the provider request is the same (in a format whose sentences don’t join into one file, such as Opus or FLAC, the whole text is one entry).

Settings stored at the provider can change under the same name: a Sarvam pronunciation dictionary (dict_id), an ElevenLabs voice’s stored settings, an ElevenLabs dictionary named without a version, a Cartesia pronunciation dictionary (pronunciation_dict_id). The cache keys them by name, not content: after you change one, sentences cached before keep their audio until they go unused for your retention period (use a new name to hear the change at once, or turn retention off, which deletes cached audio within about two days).

How long it is kept#

Your org’s retention, set under Settings: 30 days by default, 1 to 30 days, or 0 (off).

  • It counts from when the audio was last used, so audio your agents keep playing stays cached. Audio is deleted within your retention plus one day of its last use.
  • A change applies to everything already cached: lowering it deletes older audio, raising it keeps audio longer.
  • At 0, nothing new is cached and cached audio is deleted within about two days. Requests still work, every sentence synthesized by the provider.

What isn’t cached#

  • Text. Audio is stored under a one-way hash of the sentence and its settings. The sentence itself is never stored or logged.
  • Anything incomplete: a sentence that failed, timed out or was cut off. When your agent is interrupted, the provider stops the sentence in progress, so it isn’t cached (ElevenLabs finishes it, and it is); sentences not yet sent are dropped. When a client disconnects instead, a sentence already being synthesized finishes and is cached.
  • Sentences the provider can’t speak, which are skipped rather than failing the reply: for Sarvam, a sentence with no letter or digit (an emoji alone); for Raya, punctuation alone.
  • A sentence using a Sarvam pronunciation dictionary for the first time, until the router has read the dictionary (a moment later). It is synthesized and played, just not cached.
  • Voice lists, always read live from the provider.

Ways to connect#

Every way in uses your org's cache and stored provider keys.

Where speech is served#

One host serves every provider, from one cache per org.

HostWhereServes
api.media.ttscacherouter.devMumbai, IndiaEvery provider: the plugins, the provider drop-ins, /v1/stream, /v1/audio/speech and /v1/voices

Our LiveKit plugin and Pipecat service use it unless you set a base_url. api.in.ttscacherouter.dev and api.us.ttscacherouter.dev are older names for the same host and keep working, with the same cache. api.ttscacherouter.dev serves the dashboard and the account API (/v1/provider-keys), never speech.