so I am using google for TTS service in my voice a...
# ask-ai
e
so I am using google for TTS service in my voice ai agent but when the text is too long the agents suddenly stops speaking after further debugging through logs I found out that the TTS is timeout and the audio inoput was not being sent. by default I think the TTS should stream the text and hence dont face thius issue. here is my code settings for TTS: tts = google.TTS(_voice_name_="en-US-Chirp3-HD-Sadachbia", language="en-US")
t
Thanks for reaching out, Vivek. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you're running into timeout issues with Google TTS in your voice AI agent, no worries — here are some friendly tips to help you out: • Enable Streaming Synthesis: Google TTS streams text by default, which means it processes the text in smaller chunks to avoid those pesky timeouts. Just make sure your TTS instance looks like this:
Copy code
from 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:
Copy code
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:
Copy code
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:
Copy code
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.py
e
what is the library for this: tokenizer=tokenize.blingfire.SentenceTokenizer
t
The
tokenizer=tokenize.blingfire.SentenceTokenizer
comes from the livekit.agents.tokenize.blingfire module. You can easily import and use it like this:
Copy code
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!