jolly-apartment-95291
11/08/2025, 2:14 AMtall-airline-16756
11/08/2025, 2:14 AMtall-airline-16756
11/08/2025, 2:14 AMsynthesize() method from the TTS class in the LiveKit Agents framework. This method sends your entire text to Cartesia’s /tts/bytes API endpoint and returns the audio either fully or in large chunks, which works perfectly for non-streaming scenarios.
Here’s a simple way to get started:
1. Install the LiveKit Agents plugin for Cartesia:
uv add "livekit-agents[cartesia]~=1.2" (Python)
pnpm add @livekit/agents-plugin-cartesia@1.x (Node.js)
2. Set your Cartesia API key:
You can set the environment variable CARTESIA_API_KEY or pass it directly when you create the TTS object.
3. Use the synthesize() method:
Here’s an example in Python:
from livekit.plugins import cartesia
import asyncio
async def main():
tts = cartesia.TTS(model="sonic-2", voice="your-voice-id", sample_rate=24000)
stream = tts.synthesize("Hello, this is a complete non-streaming response.")
async for audio in stream:
print(f"Generated audio frame with {len(audio.frame.data)} samples")
if __name__ == "__main__":
asyncio.run(main())
If you want to explore more advanced options, like customizing voices or choosing specific models, just let me know—I’m here to help with any details you need!
Sources: examples/voice_agents/tts_text_pacing.py | plugins/cartesia/src/tts.ts | Cartesia TTS plugin guide | LiveKit Docs | Text-to-speech (TTS) models | LiveKit Docs | Cartesia TTS | LiveKit docsjolly-apartment-95291
11/08/2025, 2:16 AMtall-airline-16756
11/08/2025, 2:17 AMcartesia.TTS, you’ll want to use the synthesize() method instead of stream(). The great thing about synthesize() is that it automatically uses the non-streaming /tts/bytes endpoint, which is perfect for generating the full audio without streaming.
Here’s a simple way to set it up:
1. Initialize the TTS object:
tts = cartesia.TTS(
api_key="your_api_key", # or set CARTESIA_API_KEY env var
model="sonic-2",
voice="your-voice-id",
encoding="pcm_s16le",
sample_rate=24000,
)
2. Use the synthesize() method:
audio_stream = tts.synthesize("Hello, this is non-streaming audio.")
# This uses the non-streaming /tts/bytes endpoint
Just a quick note: there isn’t a specific flag like streaming=False in the TTS class. Instead, whether the audio streams or not depends on if you call synthesize() (for non-streaming) or stream() (for streaming).
If you have any questions or want me to walk you through it, just let me know—I’m here to help!
Sources: Pipeline nodes and hooks | LiveKit docs | examples/voice_agents/timed_agent_transcript.py | plugins/cartesia/src/tts.ts