How do I use a custom TTS with the agentsession pi...
# ask-ai
d
How do I use a custom TTS with the agentsession pipeline
t
Thanks for reaching out, Harsha. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
If you want to use a custom Text-to-Speech (TTS) provider with the
AgentSession
pipeline in LiveKit, you’ve got a few great options to choose from: 1. Using Pre-Built TTS Plugins: LiveKit supports providers like Cartesia, ElevenLabs, PlayHT, Groq, and OpenAI-compatible endpoints. You can easily get started by initializing the
AgentSession
with a TTS instance from these plugins. For example, here’s how you’d do it with Cartesia:
Copy code
from livekit.plugins import cartesia
session = AgentSession(tts=cartesia.TTS(model="sonic-english"))
1. Using OpenAI-Compatible Custom Endpoints: If your custom TTS service offers an OpenAI-style API, you can use the
openai_plugin.TTS
and just point it to your custom
base_url
like this:
Copy code
from livekit.plugins import openai as openai_plugin
tts_instance = openai_plugin.TTS(
  model="custom-model",
  voice="custom-voice",
  base_url="http://your-custom-tts-service:8000/v1"
)
1. Implementing a Fully Custom TTS Provider: If you want full control, you can override the
tts_node
method in your custom agent. This way, you can handle the text however you want before sending it off to your TTS engine.
Copy code
from livekit.agents import Agent
class CustomTtsAgent(Agent):
    async def tts_node(self, text, model_settings):
        async for chunk in text:
            yield f""
1. Standalone TTS Streaming: You can also use TTS on its own to stream audio directly into a room track. If you want, I’m here to help you pick the best option or dive deeper into any of these methods. Just let me know! Sources: Text-to-speech (TTS) integrations | LiveKit Docs | PlayHT integration guide | LiveKit Docs | Groq TTS integration guide | LiveKit Docs | ElevenLabs TTS integration guide | LiveKit Docs | examples/voice_agents/realtime_with_tts.py
d
I want to use this as a custom TTS - from sarvamai import SarvamAI from sarvamai.play import save client = SarvamAI(api_subscription_key="") # Convert text to speech audio = client.text_to_speech.convert( target_language_code="kn-IN", #text="Hi there! This is Praveen from Expressbee. Would you like to track your shipment? Please tell me your tracking ID", #text="ಇದು ಕಿಮ್ಮನೆ ಲಗ್ಜುರಿ ರೆಸಾರ್ಟ್‌ನ ಅನಿಶಾ ಮಾತನಾಡುತ್ತಿದ್ದೇನೆ. ನಾನು ಇಂದು ನಿಮಗೆ ಹೇಗೆ ಸಹಾಯ ಮಾಡಬಹುದು?", text="This is anisha from kimmane luxury resort. How can i help you today?", #text="ನಮಸ್ಕಾರ, ಕಿಮ್ಮಣೆ Luxury Resort ಗೆ ಸ್ವಾಗತ. ನಾನು ಅನಿಷಾ ಮಾತನಾಡುತ್ತಿದ್ದೇನೆ, ಇಂದು ನಾನು ನಿಮಗೆ ಹೇಗೆ ಸಹಾಯ ಮಾಡಲಿ?", model="bulbul:v3-beta", enable_preprocessing=True, speaker="ritu", # sakshi, harsh, aditya, chirag, ritu speech_sample_rate=16000, ) save(audio, "output2.wav")
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
d
No, can use show how I can use Sarvamai python sdk for a custom TTS