When I switch from using Cartesia to ElevenLabs fo...
# ask-ai
d
When I switch from using Cartesia to ElevenLabs for TTS I stop getting any audio playback in the browser. I’ve definitely got an ELEVEN_API_KEY set, and I’m running pn download-files to make sure the necessary files are available. There are no error messages in the agent logs. I’m using the JS/TS SDK. Any ideas?
t
Thanks for reaching out, Chris. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! When switching from Cartesia to ElevenLabs for TTS, sometimes audio playback hiccups can happen because of differences in audio settings and how browsers handle audio. Don’t worry though—let’s walk through some steps together to help fix this: 1. Standardize Audio Configuration: It’s a good idea to make sure both providers are using the same sample rates and encoding formats. For example, setting the sample rate to 24000 and encoding to 'pcm_s16le' can keep things consistent. 2. Stream Cleanup: Before starting with the new provider, make sure to properly close the current TTS stream and WebSocket connection. This helps avoid any conflicts. 3. Reset Audio Context: Sometimes, closing and reinitializing the browser’s audio context when switching providers can prevent format mismatches and playback issues. 4. Provider Switching Pattern: Having a clear, structured way to manage switching between TTS providers—cleaning up and reinitializing properly—can make the transition smooth. To help me better understand what’s going on, could you please let me know: • Are you explicitly setting matching audio configurations for both providers? • Do you notice any errors or warnings in your browser’s console? • Is the audio context in a valid state when playback doesn’t work? With these details, we can get to the bottom of this and make sure your audio plays smoothly. I’m here to help every step of the way! Sources: agents/src/voice/agent_activity.ts
d
I’m not explicitly setting matching audio configurations. How do I do that?
t
To help you set matching audio configurations for Cartesia and ElevenLabs TTS, it’s important to align key parameters like sample rate and encoding. Let me walk you through how you can do this: Cartesia Example:
Copy code
import * 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:
Copy code
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:
Copy code
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