Skip to main content

pipecat-tts-cache-router

Pipecat TTS service for tts-cache-router: Sarvam, Raya, ElevenLabs, OpenAI, Deepgram, xAI, Soniox, Smallest AI and Cartesia text-to-speech, with every sentence your bot has said before served from a per-account cache.

Same output whether you call the provider directly or through the router: each sentence reaches the provider verbatim with your exact settings, and a cache hit replays a real provider take for that exact request.

Full documentation: docs.ttscacherouter.dev/pipecat. For LLMs and coding agents: llms.txt, and this page as Markdown at pipecat.md.

Tested with Pipecat v1.12.0. Maintained by Oggnai Technologies, the company that runs tts-cache-router.

Install

pip install pipecat-tts-cache-router

Usage

import os

from pipecat_tts_cache_router import TTSCacheRouterTTSService

tts = TTSCacheRouterTTSService(
    api_key=os.environ["TTS_CACHE_ROUTER_API_KEY"],
    settings=TTSCacheRouterTTSService.Settings(
        model="sarvam/bulbul:v3", voice="shubh", language="hi-IN"
    ),
)

pipeline = Pipeline(
    [transport.input(), stt, user_aggregator, llm, tts, transport.output(), assistant_aggregator]
)

Before the first request, store your Sarvam, Raya, ElevenLabs, OpenAI, Deepgram, xAI, Soniox, Smallest AI or Cartesia API key in the dashboard at ttscacherouter.dev. The router keeps it encrypted and uses it only to call that provider for your requests. Your bot authenticates with your router API key alone, from the same dashboard.

TTSCacheRouterTTSService(...)

Argument Default
api_key required your router API key
settings required TTSCacheRouterTTSService.Settings(...), below
base_url wss://api.ttscacherouter.dev set to your own router when self-hosting
sample_rate the pipeline's output rate one the provider streams: 8000, 16000, 22050 or 24000 for most; see Models and options

Other keyword arguments go to Pipecat's WebsocketTTSService, except text_aggregation_mode: the router splits the text into sentences itself, so the service streams the LLM's text to it as it arrives.

TTSCacheRouterTTSService.Settings(...)

The settings are in the router's own names, the same for every provider:

Setting
model required "<provider>/<model>": "sarvam/bulbul:v3", "raya/standard", "elevenlabs/eleven_flash_v2_5", "openai/gpt-4o-mini-tts", "deepgram/aura-2", "xai/xai-tts", "soniox/tts-rt-v2", "smallestai/lightning_v3.1_pro", "cartesia/sonic-3", …
voice required the provider's voice id (GET /v1/voices lists them)
language None the provider's own language code, where it takes one ("hi-IN" for Sarvam, "hi" for Raya, "en" for the rest)
speed None the speaking rate, where the provider takes one
options {} the provider's other settings, e.g. {"temperature": 0.6} for Sarvam, {"voice_settings": {"stability": 0.5}} for ElevenLabs, {"instructions": "Speak warmly."} for OpenAI

Every provider's models, voices, languages and options are in Models and options. The router checks the settings when the pipeline starts, so a wrong one is reported then as an ErrorFrame.

Changing settings mid-session

from pipecat.frames.frames import TTSUpdateSettingsFrame

await worker.queue_frame(
    TTSUpdateSettingsFrame(delta=TTSCacheRouterTTSService.Settings(voice="priya"))
)

Replies that start afterwards use the new settings. A model of another provider starts from no language, speed or options unless the update gives them.

Interruptions

When the user interrupts, the service tells the router to stop the reply, and the provider stops the sentence it was synthesizing. The next reply starts on the same connection.

Transcripts

The service's TTSTextFrames follow the audio: each sentence's words as its audio starts, or word by word with ElevenLabs and Cartesia.

Metrics

With usage metrics on, each reply's TTSUsageMetricsData counts only the characters the provider synthesized (and billed); sentences served from the cache count zero. Its model is "<provider>/<model>".

Once a reply is all sent, the service also calls its on_cache_stats handlers with a CacheStats: the reply's context_id, sentences, cached_sentences, characters and billed_characters (and cached_characters, the difference):

@tts.event_handler("on_cache_stats")
async def on_cache_stats(tts, stats):
    print(stats.cached_sentences, "of", stats.sentences, "sentences from the cache")

An interrupted reply reports both too, counting the sentences the router sent in full before the interruption. This needs a router that reports them (the hosted router does); with an older one, the service logs an error and reports nothing for the interrupted reply.

Example

examples/pipecat_agent.py is a complete bot: Deepgram speech-to-text, an OpenAI LLM and this service, on Pipecat's local WebRTC runner. With TTS_CACHE_ROUTER_API_KEY, DEEPGRAM_API_KEY and OPENAI_API_KEY set:

cd examples
uv run pipecat_agent.py

Then open http://localhost:7860/client and talk to it.

License

Apache-2.0.

Metadata

Release files for pipecat-tts-cache-router 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pipecat-tts-cache-router 0.1.1
File Size Uploaded
pipecat_tts_cache_router-0.1.1.tar.gz 18.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pipecat-tts-cache-router 0.1.1
File Interpreter ABI Platform
pipecat_tts_cache_router-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 37.7 kB

Release files / pipecat_tts_cache_router-0.1.1.tar.gz

Download URL pipecat_tts_cache_router-0.1.1.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c60dbbcce3b3fe7d4d8cbc0f00ef6634883b0c8d02452fd0ef33a4f793cb2cb8
BLAKE2b-256 checksum
How to use checksums
a703dbc0cfd760297237c16dddb1f59d273e50686c85b1d183a59ec11cb42a7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / pipecat_tts_cache_router-0.1.1-py3-none-any.whl

Download URL pipecat_tts_cache_router-0.1.1-py3-none-any.whl
Size 19.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
818cbdafa34b3b2b0f34be7024c7841c2fc1ed430f8b144d927606e24d18a099
BLAKE2b-256 checksum
How to use checksums
3f63dfb3111e78701b96fffd77c06555c221bc6ecfe5938ad39e09f91de6af53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page