busy-lunch-15701
11/05/2025, 10:19 AMtall-airline-16756
11/05/2025, 10:19 AMtall-airline-16756
11/05/2025, 10:20 AMmodalities = ["text"]) and include a TTS instance in your AgentSession. This routes the model’s text into your TTS. Realtime models, TTS models, OpenAI Realtime plugin
2. Modify the text before TTS by overriding one of these nodes in your Agent:
◦ transcription_node: adjust/post-process text segments (cleanup, replacements, add SSML) before forwarding to TTS.
◦ tts_node: control chunking and apply provider-specific formatting/SSML right before synthesis. Pipeline nodes and hooks
Would you like a short code sketch (Node or Python) showing a transcription_node or tts_node override that rewrites the text before TTS?
Sources: Realtime model plugins | LiveKit Docs | Text-to-speech (TTS) models | LiveKit Docs | Pipeline nodes and hooks | LiveKit docs | OpenAI Realtime API plugin guide | LiveKit docs | AI Agents Framework | livekit/livekit_composite | DeepWikibusy-lunch-15701
11/05/2025, 10:25 AMbusy-lunch-15701
11/05/2025, 10:25 AMtall-airline-16756
11/05/2025, 10:27 AMfrom livekit import agents, llm
class CleanOutputAgent(agents.Agent):
async def llm_node(self, chat_ctx):
# Call default LLM node, intercept streamed chunks, clean them, forward to TTS
async for chunk in agents.Agent.default.llm_node(self, chat_ctx):
text = chunk if isinstance(chunk, str) else getattr(chunk, "text", "")
if not text:
yield chunk
continue
# Example edits: strip tags, add SSML, fix phrasing, etc.
cleaned = (
text.replace("<think>", "")
.replace("</think>", "")
.replace("uh,", "")
)
if isinstance(chunk, llm.ChatChunk):
yield llm.ChatChunk(text=cleaned, meta=getattr(chunk, "meta", None))
else:
yield cleaned
async def main():
# Realtime model should respond with text only
rt_model = {
"provider": "openai-realtime", # example provider
"modalities": ["text"],
# ... provider-specific config (model, api key via env, etc.)
}
# Cartesia TTS configuration (model + voice; add extras if desired)
cartesia_tts = {
"model": "cartesia/sonic-3",
"voice": "YOUR_CARTESIA_VOICE_ID",
# Optional extras (if supported): "language": "en-US", "extra_kwargs": {"speed": 1.0}
}
agent = CleanOutputAgent()
session = agents.AgentSession(
agent=agent,
llm=rt_model,
tts=cartesia_tts,
)
await session.start()
# ... connect your media/IO as usual
if __name__ == "__main__":
import asyncio
asyncio.run(main())
• Set the realtime model to text-only so the pipeline can modify text before TTS Realtime models.
• Intercept and edit text in llm_node (or use `transcription_node`/`tts_node`) before synthesis Pipeline nodes.
• Configure Cartesia via the session tts descriptor (model, voice, optional params) Cartesia TTS.
Want a variant that applies SSML or moves the logic into tts_node for chunking/pronunciation?
Sources: Pipeline nodes and hooks | LiveKit docs | Cartesia TTS | LiveKit docs | Realtime model plugins | LiveKit Docs | Cartesia TTS plugin guide | LiveKit Docs | Modifying LLM output before TTS | LiveKit Docs