eager-crowd-1678
08/13/2025, 12:17 PMtall-airline-16756
08/13/2025, 12:17 PMtall-airline-16756
08/13/2025, 12:18 PMfrom livekit.plugins import google
tts = google.TTS(
use_streaming=True, # Streaming is on by default
tokenizer=tokenize.blingfire.SentenceTokenizer() # Using the default tokenizer
)
• Configure Timeout Settings: Sometimes, you might need a bit more time for longer texts. You can tweak the timeout settings like this: from livekit.agents import APIConnectOptions
conn_options = APIConnectOptions(timeout=30.0) # Giving it a 30-second timeout
# Use this with streaming
tts_stream = tts.stream(conn_options=conn_options)
• Limit Text Length: To keep things manageable, you can create a custom agent that limits how much text gets processed at once. Here’s a handy example: class ShortRepliesOnlyAgent(Agent):
async def tts_node(self, text: AsyncIterable[str], model_settings: ModelSettings):
MAX_CHUNKS = 20
chunk_count = 0
async def process_text():
nonlocal chunk_count
interrupted = False
async for chunk in text:
chunk_count += 1
if chunk_count > MAX_CHUNKS and not interrupted:
self.session.interrupt()
self.session.say("I'm sorry, that will take too long to say.")
interrupted = True
break
if not interrupted:
yield chunk
return Agent.default.tts_node(self, process_text(), model_settings)
• Use Text Pacing: Another neat trick is enabling text pacing to smoothly handle longer inputs: from livekit.agents import tts
tts_with_pacing = tts.StreamAdapter(
tts=google.TTS(),
text_pacing=True, # This uses the default pacing setup
)
Give these a try, and your voice AI agent should handle longer texts much more gracefully without timing out. If you get stuck or have questions, I'm here to help!
Sources: livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/tts.py | pipeline-tts/short_replies_only.pyeager-crowd-1678
08/13/2025, 12:28 PMtall-airline-16756
08/13/2025, 12:29 PMtokenizer=tokenize.blingfire.SentenceTokenizer comes from the livekit.agents.tokenize.blingfire module. You can easily import and use it like this:
from livekit.agents.tokenize.blingfire import SentenceTokenizer
If you have any questions or need a hand with it, just let me know—I’m here to help!