delightful-agency-7843
10/10/2025, 6:06 AMtall-airline-16756
10/10/2025, 6:06 AMtall-airline-16756
10/10/2025, 6:07 AMdelightful-agency-7843
10/10/2025, 6:13 AMtall-airline-16756
10/10/2025, 6:13 AMimport * as cartesia from '@livekit/agents-plugin-cartesia';
const cartesiaTTS = new cartesia.TTS({
model: 'sonic-2',
voice: 'your-voice-id',
sampleRate: 24000,
encoding: 'pcm_s16le',
apiKey: process.env.CARTESIA_API_KEY,
});
ElevenLabs Example:
import * as elevenlabs from '@livekit/agents-plugin-elevenlabs';
const elevenlabsTTS = new elevenlabs.TTS({
voiceId: 'your-voice-id',
sampleRate: 24000, // Match Cartesia's sample rate
encoding: 'pcm_s16le',
apiKey: process.env.ELEVEN_API_KEY,
});
It’s really important to make sure both providers use the same sample rate (like 24000 Hz) and encoding ('pcm_s16le') so you don’t run into any playback problems.
If you’re working with LiveKit Inference, you can actually configure both providers easily through a unified interface, which helps keep things consistent:
import { inference } from '@livekit/agents';
const commonOptions = {
encoding: 'pcm_s16le',
sampleRate: 24000,
apiKey: process.env.LIVEKIT_API_KEY,
};
const cartesiaTTSInference = new inference.TTS({
model: 'cartesia/sonic-2',
voice: 'your-voice-id',
...commonOptions,
});
const elevenlabsTTSInference = new inference.TTS({
model: 'elevenlabs/eleven_turbo_v2_5',
voice: 'your-voice-id',
...commonOptions,
});
Using LiveKit Inference really simplifies the setup and helps ensure your audio sounds great across both providers. If you have any questions or need a hand with anything else, please don’t hesitate to reach out—I’m here to help!
Sources: examples/src/comprehensive_test.ts | ElevenLabs TTS plugin guide | LiveKit Docs | pipeline-tts/tts_comparison/README.md