early-restaurant-74591
10/13/2025, 12:33 AMtall-airline-16756
10/13/2025, 12:33 AMtall-airline-16756
10/13/2025, 12:34 AMtts = cartesia.TTS(
text_pacing=True, # Enable default pacer
# or use custom pacer
text_pacing=tts.SentenceStreamPacer()
)
2. Resolving 'APIConnectionError':
• Double-check that your Cartesia API key is correctly set, either in your environment variables or passed directly like this:
# Set in environment
CARTESIA_API_KEY=your_api_key_here
# Or pass directly
tts = cartesia.TTS(api_key="your_api_key_here")
• If your connection is slow, try increasing the timeout settings:
from livekit.agents import APIConnectOptions
conn_options = APIConnectOptions(timeout=30.0) # Increase timeout
stream = tts.synthesize("text", conn_options=conn_options)
• Prewarming the connection pool can also help prevent session issues:
tts.prewarm() # Prewarm the connection pool
• Lastly, make sure the base URL is accessible and correctly configured:
tts = cartesia.TTS(
base_url="https://api.cartesia.ai" # Default, but can be customized
)
Additional Steps:
• Turning on detailed logging can give us more insight if problems persist:
import logging
logging.getLogger("livekit.plugins.cartesia").setLevel(logging.DEBUG)
• Also, it’s a good idea to check your Cartesia API dashboard to review your quota limits, service status, and permissions.
If you try these suggestions and still face issues, please don’t hesitate to reach out. I’m here to support you and we can explore other solutions together!
Sources: livekit-plugins/livekit-plugins-sarvam/livekit/plugins/sarvam/tts.py | Cartesia TTS plugin guide | LiveKit Docsearly-restaurant-74591
10/13/2025, 3:56 PMtall-airline-16756
10/13/2025, 3:58 PMuse_tts_aligned_transcript=True in the AgentSession configuration. This will help you log the text chunks being sent to the TTS engine along with timing metadata:
async def transcription_node(
self, text: AsyncIterable[str | TimedString], model_settings: ModelSettings
) -> AsyncGenerator[str | TimedString, None]:
async for chunk in text:
if isinstance(chunk, TimedString):
logger.info(f"TimedString: '{chunk}' ({chunk.start_time} - {chunk.end_time})")
else:
logger.info(f"Text chunk: '{chunk}'")
yield chunk
2. Monitor Transcription Output:
Agents publish transcriptions to the lk.transcription text stream topic. You can register handlers to receive and log these streams using the LiveKit SDKs, which is quite handy.
3. Client-Side Text Stream Logging:
If you’re working on a frontend application, you can set up text stream logging to capture and log text streams published by the agent. For example, in a React app, you might do:
room.registerTextStreamHandler('lk.transcription', handler);
Please feel free to reach out if you'd like any help implementing these methods or if you have any questions along the way. I'm here to support you!
Sources: avatars/hedra/education_avatar/education-frontend/hooks/useTextStreamLogger... | Sending text | LiveKit Docs | Text and transcriptions | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.pyearly-restaurant-74591
10/13/2025, 4:05 PMtall-airline-16756
10/13/2025, 4:05 PMearly-restaurant-74591
10/13/2025, 4:05 PMtall-airline-16756
10/13/2025, 4:05 PMearly-restaurant-74591
10/13/2025, 4:06 PMbash
:arrows_counterclockwise: TTS NODE START: Processing text stream
:arrows_counterclockwise: TTS NODE FINAL TEXT: ''
:mag: TEXT PIPELINE [TTS_NODE_FINAL]: ''
:mag: TEXT ANALYSIS [TTS_NODE_FINAL]:
- Length: 0
- Stripped length: 0
- Has alphanumeric: False
- Is only punctuation: False
- Raw bytes: b''
- Character codes: []
This pattern appears multiple times in your logs, showing that the TTS node is receiving completely empty text streams initially.
## 🎯 The Issue Explained
1. Empty Stream Detection: The TTS_NODE_FINAL text is empty (Length: 0)
2. No Content: Has alphanumeric: False and Is only punctuation: False
3. Empty Bytes: Raw bytes: b'' shows completely empty content
4. No Characters: Character codes: [] shows no characters at all
## 🔄 What Happens Next
After the empty stream, the chunks start coming through properly:
bash
:arrows_counterclockwise: TTS CHUNK: 'Hi' (length: 2)
:arrows_counterclockwise: TTS CHUNK: ' -' (length: 2)
:arrows_counterclockwise: TTS CHUNK: ' I' (length: 2)
# ... more chunks follow
## 🚨 Why This Causes Cartesia Errors
Cartesia receives the empty stream first before the actual text chunks arrive. This triggers the "transcript empty or contains only punctuation" error because:
1. Cartesia gets an empty text stream initially
2. It tries to process the empty content
3. It fails with the error you're seeing
4. Then the actual text chunks arrive (too late)
## 💡 The Fix Needed
The issue is that the TTS node is processing an empty stream before the actual text is ready. This is a timing/streaming issue where Cartesia gets called with empty content before the real text arrives.
This explains why you get the Cartesia errors intermittently - it depends on the timing of when the empty stream vs. the actual text chunks arrive at the TTS system.tall-airline-16756
10/13/2025, 4:09 PMdef validate_text_chunk(chunk: str) -> bool:
if not chunk or not chunk.strip():
return False
if len(chunk.strip().split()) < 2: # Less than 2 words
return False
return True
2. Configure Tokenizer Settings:
• Using a properly set-up tokenizer can really help with breaking down your text chunks effectively:
from livekit.agents import tokenize
tokenizer = tokenize.blingfire.SentenceTokenizer()
3. Handle Streaming Properly:
• It's best to buffer your text and send it in meaningful chunks rather than character-by-character or tiny fragments. Here’s an example:
# Example of chunking text
words = text.split()
for i in range(0, len(words), 2):
chunk = " ".join(words[i : i + 2])
if chunk:
stream.push_text(chunk + " ")
4. Use StreamAdapter for Consistency:
• If you find timing issues are still popping up, wrapping your TTS instance with a StreamAdapter can help manage streaming more predictably:
from livekit.agents.tts import StreamAdapter
tts_wrapped = StreamAdapter(tts=tts, sentence_tokenizer=tokenizer)
stream = tts_wrapped.stream()
5. Monitor and Debug:
• Turning on detailed logging can give you a clearer picture of what’s being sent to Cartesia:
import logging
logging.getLogger("cartesia").setLevel(logging.DEBUG)
• Keep an eye out for any warnings about empty or invalid chunks in the logs.
By following these steps, you should be able to make sure Cartesia receives meaningful text streams and avoid the "transcript empty or contains only punctuation" error. If you hit any snags or want to chat more about this, just let me know—I’m here to help!
Sources: plugins/cartesia/src/tts.ts | livekit-agents/livekit/agents/inference/tts.py