Cartesia

Updated

Use Cartesia for text-to-speech (TTS) in a Conversational AI Platform agent.

Preview documentation

You're reading the Conversational AI Platform (Preview) docs. Switch to Main.

Cartesia provides ultra-fast, low-latency text-to-speech with real-time streaming capabilities, optimized for interactive conversational AI applications.

Sample configuration

The following example shows how to configure Cartesia as the agent's TTS when you create or update an agent. For a complete example, see Create an agent and start a session.

Cartesia supports BYOK only. It isn't available in managed mode. Store your Cartesia API key in a secret set, and refer to it from the agent. For details, see Use your own provider keys.

from agora_agent import Agent, CartesiaTTS, secret_ref

# client is your configured Agora client
agent = (
    Agent(client=client)
    .with_stt(...)  # configure your ASR vendor
    .with_llm(...)  # configure your LLM vendor
    .with_tts(
        CartesiaTTS(
            api_key=secret_ref("support_prod", "cartesia"),
            base_url="wss://api.cartesia.ai",
            model_id="sonic-2",
            voice_id="<voice_id>",
            sample_rate=16000,
            language="en",
        )
    )
)
import { Agent, CartesiaTTS, secretRef } from 'agora-agents';

// client is your configured Agora client
const agent = new Agent({ client })
  .withStt(/* configure your ASR vendor */)
  .withLlm(/* configure your LLM vendor */)
  .withTts(
    new CartesiaTTS({
      apiKey: secretRef('support_prod', 'cartesia'),
      baseUrl: 'wss://api.cartesia.ai',
      modelId: 'sonic-2',
      voiceId: '<voice_id>',
      sampleRate: 16000,
      language: 'en',
    }),
  );
// client is your configured Agora client
sampleRate := vendors.SampleRate16kHz
agent := agentkit.NewAgent(client).
	WithStt( /* configure your ASR vendor */ ).
	WithLlm( /* configure your LLM vendor */ ).
	WithTts(vendors.NewCartesiaTTS(vendors.CartesiaTTSOptions{
		APIKey:     agentkit.SecretRef("support_prod", "cartesia"),
		BaseURL:    "wss://api.cartesia.ai",
		ModelID:    "sonic-2",
		VoiceID:    "<voice_id>",
		SampleRate: &sampleRate,
		Language:   "en",
	}))

Set credential.mode to byok and credential.fields.api_key to a reference to your Cartesia API key. In the following example, the key is stored as cartesia in the support_prod set:

"tts": {
  "credential": {
    "mode": "byok",
    "fields": {
      "api_key": "$secrets.support_prod.cartesia"
    }
  },
  "vendor": "cartesia",
  "url": "wss://api.cartesia.ai",
  "params": {
    "model_id": "sonic-2",
    "voice": {
      "mode": "id",
      "id": "<voice_id>"
    },
    "output_format": {
      "container": "raw",
      "sample_rate": 16000
    },
    "language": "en"
  }
}

Key parameters

The tts block takes the following fields. In the SDKs, CartesiaTTS sets them from its options.

tts
vendorstring
required

Set to cartesia.

credentialobject
required

Set mode to byok and fields.api_key to a $secrets.<set>.<key> reference to your Cartesia API key. Get your API key from the Cartesia Console.

urlstring
optional

The WebSocket URL for the Cartesia streaming API. For example, wss://api.cartesia.ai.

paramsobject
required
model_idstring
required

The identifier of the TTS model to use. For example, sonic-2.

voiceobject
required

Voice configuration object.

modestring
required

Voice selection mode. Use id to select by voice identifier.

idstring
required

The identifier of the selected voice for speech synthesis.

output_formatobject
optional

Audio output format configuration

containerstring
optional

Audio container format for the output stream.

sample_ratenumber
optional
Default value
16000
Possible values
  • 8000
  • 16000
  • 22050
  • 24000
  • 44100
  • 48000

Audio sampling rate in Hz

languagestring
optional

Target language for speech synthesis.

Caution

The parameters listed on this page are validated for use with the Conversational AI Platform. Required parameters must be provided as documented. Any additional parameters in params are passed through directly to Cartesia without validation. For a full list of supported options, refer to the Cartesia TTS documentation.

This integration is fully supported for use with the Conversational AI Platform. While it has completed functional validation, it is newer to the platform, and additional provider-specific edge cases may be identified as usage scales across a broader range of applications and workloads.