dry-rainbow-66344
09/02/2025, 8:36 AMtall-airline-16756
09/02/2025, 8:36 AMtall-airline-16756
09/02/2025, 8:37 AMfrom livekit.agents import AgentSession
from livekit.plugins import cartesia
session = AgentSession(
tts=cartesia.TTS(model="sonic-2", voice="f786b574-daa5-4673-aa0c-cbe3e8534c02")
)
• Using OpenAI-Compatible Endpoints: If your custom TTS has an OpenAI-compatible API, you can use the openai.TTS plugin with your own base URL like this:
from livekit.plugins import openai
tts = openai.TTS(
model="custom-model",
voice="custom-voice",
base_url="http://localhost:8880/v1",
response_format="wav"
)
session = AgentSession(tts=tts)
• Overriding the tts_node Method: If you want to get a bit more hands-on, you can override the tts_node method in your custom Agent class to tweak the text before it’s turned into speech. Sources: Text-to-speech (TTS) integrations | LiveKit Docs | Resemble AI TTS integration guide | LiveKit Docs | Hume TTS integration guide | LiveKit Docs | LMNT TTS integration guide | LiveKit Docs | pipeline-tts/rime_tts.pydry-rainbow-66344
09/02/2025, 8:39 AMtall-airline-16756
09/02/2025, 8:39 AMfrom livekit.agents.voice import TTS
class SarvamAITTS(TTS):
def __init__(self, api_key):
self.client = SarvamAI(api_subscription_key=api_key)
async def stream(self, text, **kwargs):
audio = self.client.text_to_speech.convert(
target_language_code="kn-IN",
text=text,
model="bulbul:v3-beta",
enable_preprocessing=True,
speaker="ritu",
speech_sample_rate=16000,
)
yield audio # Just make sure this yields audio chunks in the format LiveKit expects
1. Integrate with AgentSession: Then, pass your custom TTS class right into the AgentSession.
from livekit.agents import AgentSession
session = AgentSession(
tts=SarvamAITTS(api_key="sk_gfe5pjqs_8V4aBdsutdrrb3QmMQqyVJgF")
)
1. Test and Debug: Finally, double-check that the audio output matches what your playback setup needs. You might need to tweak the format or sample rate a bit to get everything working perfectly with LiveKit.
If you hit any bumps or want a hand with the implementation or testing, just give me a shout—I’m here to help!dry-rainbow-66344
09/02/2025, 8:44 AMtall-airline-16756
09/02/2025, 8:45 AM