> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zeroruntime.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Cartesia

> Python API reference for the cartesia text-to-speech plugin.

<Card title="Usage guide" icon="book" href="/plugins/tts/cartesia" horizontal>
  Setup, environment variables, and Python/JavaScript/Go usage examples.
</Card>

## CartesiaTTSModel

```python theme={null}
CartesiaTTSModel = typing.Literal['sonic-3.5', 'sonic-3', 'sonic-2', 'sonic-turbo']
```

***

## CartesiaTTS

Cartesia Text-to-Speech provider.

Synthesizes speech using Cartesia's Sonic neural TTS models via streaming
WebSocket, delivering low-latency audio in PCM format.  Voices can be
specified by catalog UUID or by a raw voice-embedding vector for
voice-cloning use cases.  Fine-grained generation controls (speed,
emotion, volume) are available on `sonic-3` and newer models.

### Constructor

```python theme={null}
CartesiaTTS(*, api_key: 'str | None' = None, voice: 'Union[str, List[float], None]' = None, voice_id: 'Union[str, List[float], None]' = None, model: 'CartesiaTTSModel | str' = 'sonic-2', language: 'str' = 'en', sample_rate: 'int' = 24000, speed: 'Optional[float]' = None, volume: 'Optional[float]' = None, emotion: 'Optional[str]' = None, pronunciation_dict_id: 'Optional[str]' = None, max_buffer_delay_ms: 'Optional[int]' = None, enable_word_timestamps: 'Optional[bool]' = None, generation_config: 'Optional[GenerationConfig]' = None, **kwargs)
```

<ParamField path="api_key" type="str | None">
  Cartesia API key for authentication.  Falls back to the `CARTESIA_API_KEY` environment variable when omitted.
</ParamField>

<ParamField path="voice" type="Union[str, List[float], None]">
  Voice specification.  Pass a `str` UUID from the Cartesia voice catalog (e.g. `"f8f5f1b2-f02d-4d8e-a40d-fd850a487b3d"`), or a `list[float]` embedding vector for voice cloning.  Mutually exclusive with `voice_id`; `voice` takes precedence. Defaults to a built-in voice UUID when both are `None`.
</ParamField>

<ParamField path="voice_id" type="Union[str, List[float], None]">
  Alias for `voice` provided for backward compatibility. Accepts the same `str | list[float]` values.  Ignored when `voice` is set.
</ParamField>

<ParamField path="model" type="CartesiaTTSModel | str" default="sonic-2">
  Cartesia TTS model identifier.  Defaults to `"sonic-2"`. Current models: `"sonic-3.5"`, `"sonic-3"`, `"sonic-latest"`.  Generation-config params (speed, emotion, volume) require `sonic-3` or newer.  Accepts a `CartesiaTTSModel` enum value or a plain string.
</ParamField>

<ParamField path="language" type="str" default="en">
  BCP-47 / ISO 639-1 language code for synthesis. Defaults to `"en"` (English).  Cartesia Sonic supports 35+ languages including `"fr"`, `"de"`, `"es"`, `"pt"`, `"zh"`, `"ja"`, `"hi"`, `"it"`, `"ko"`, `"nl"`, `"pl"`, `"ru"`, `"sv"`, `"tr"`, and `"ar"`.
</ParamField>

<ParamField path="sample_rate" type="int" default="24000">
  Requested PCM output sample rate in Hz.  Cartesia supports `8000`, `16000`, `22050`, `24000`, `44100`, and `48000` Hz.  Defaults to `24000`. Note: the output rate is fixed; a mismatch triggers a warning.
</ParamField>

<ParamField path="speed" type="Optional[float]">
  Playback speed multiplier in the range `[0.6, 1.5]`. `1.0` is normal speed.  Overrides `generation_config.speed` when set.  Defaults to `None` (provider default). Available on `sonic-3` and newer.
</ParamField>

<ParamField path="volume" type="Optional[float]">
  Output volume multiplier in the range `[0.5, 2.0]`. `1.0` is normal volume.  Overrides `generation_config.volume` when set.  Defaults to `None`.  Available on `sonic-3` and newer.
</ParamField>

<ParamField path="emotion" type="Optional[str]">
  Emotion tag applied to the synthesized voice.  Primary values: `"neutral"`, `"calm"`, `"angry"`, `"content"`, `"sad"`, `"scared"`.  The full set contains 53 emotion variants.  Overrides `generation_config.emotion` when set. Defaults to `None`.  Available on `sonic-3` and newer.
</ParamField>

<ParamField path="pronunciation_dict_id" type="Optional[str]">
  ID of a Cartesia pronunciation dictionary for custom phoneme rules.  Overrides `generation_config.pronunciation_dict_id` when set. Defaults to `None`.
</ParamField>

<ParamField path="max_buffer_delay_ms" type="Optional[int]">
  Maximum buffering delay in milliseconds before audio is flushed, controlling the trade-off between streaming latency and audio quality.  Overrides `generation_config.max_buffer_delay_ms` when set. Defaults to `None`.
</ParamField>

<ParamField path="enable_word_timestamps" type="Optional[bool]">
  When `True`, includes per-word start/end timing in the streamed response.  Overrides `generation_config.enable_word_timestamps` when set. Defaults to `False`.
</ParamField>

<ParamField path="generation_config" type="Optional[GenerationConfig]">
  A `GenerationConfig` instance grouping all generation parameters as an alternative to flat kwargs. Flat parameters always take precedence over the corresponding `GenerationConfig` field.  Defaults to `None`.
</ParamField>

### aclose

```python theme={null}
def aclose(self) -> 'None'
```

Release any resources held by the provider.

### emit

```python theme={null}
def emit(self, event: 'T', *args: 'Any') -> 'None'
```

Emit an event, invoking all registered handlers with the given arguments.

Handlers are called in registration order. Coroutine handlers are
scheduled on the running event loop. If the emitter is closed, the call
is a no-op.

<ParamField path="event" type="T" required>
  The event to emit.
</ParamField>

### interrupt

```python theme={null}
def interrupt(self) -> 'None'
```

Interrupt and cancel the current synthesis for the active session, if any.

### off

```python theme={null}
def off(self, event: 'T', callback: 'Callable[..., Any]') -> 'None'
```

Remove a previously registered handler for an event.

If the handler is not registered for the event, the call is a no-op.

<ParamField path="event" type="T" required>
  The event the handler was registered for.
</ParamField>

<ParamField path="callback" type="Callable[..., Any]" required>
  The handler to remove.
</ParamField>

### on

```python theme={null}
def on(self, event: 'T', callback: 'Callable[..., Any] | None' = None) -> 'Callable[..., Any]'
```

Register a handler for an event.

Can be used directly by passing a callback, or as a decorator when
`callback` is omitted.

<ParamField path="event" type="T" required>
  The event to listen for.
</ParamField>

<ParamField path="callback" type="Callable[..., Any] | None">
  The handler to invoke when the event is emitted. If `None`, a decorator is returned that registers the decorated function.
</ParamField>

<ResponseField name="returns" type="Callable[..., Any]">
  The registered callback when `callback` is provided, otherwise a decorator that registers and returns the function it wraps.
</ResponseField>

### on\_first\_audio\_byte

```python theme={null}
def on_first_audio_byte(self, callback: "'Callable[[int, int], Awaitable[None] | None]'") -> 'None'
```

Register the callback invoked when the first audio byte is produced.

<ParamField path="callback" type="'Callable[[int, int], Awaitable[None] | None]'" required>
  A callable, optionally async, invoked with synthesis timing information when the first audio byte is emitted.
</ParamField>

### synthesize

```python theme={null}
def synthesize(self, text: 'Any', **kwargs: 'Any') -> 'None'
```

Synthesize the given text into speech.

Implementations should convert the text to audio. The default behavior
forwards the text to the active session for playback when one is present.

<ParamField path="text" type="Any" required>
  The text to synthesize; coerced to a string if needed.
</ParamField>

***

## GenerationConfig

Per-request generation settings for CartesiaTTS.

An alternative to supplying individual flat parameters directly to
`CartesiaTTS.__init__`.  When both a flat parameter and the
corresponding `GenerationConfig` field are set, the flat parameter
takes precedence.

### Fields

<ParamField path="speed" type="Optional[float]">
  Playback speed multiplier in the range `[0.6, 1.5]`. `1.0` is normal speed.  Defaults to `None` (provider default).
</ParamField>

<ParamField path="emotion" type="Optional[str]">
  Emotion tag applied to the synthesized voice.  Primary options include `"neutral"`, `"calm"`, `"angry"`, `"content"`, `"sad"`, `"scared"`.  Defaults to `None`.
</ParamField>

<ParamField path="volume" type="Optional[float]">
  Output volume multiplier in the range `[0.5, 2.0]`. `1.0` is normal volume.  Defaults to `None`.
</ParamField>

<ParamField path="pronunciation_dict_id" type="Optional[str]">
  ID of a Cartesia pronunciation dictionary to apply custom phoneme rules.  Defaults to `None`.
</ParamField>

<ParamField path="max_buffer_delay_ms" type="Optional[int]">
  Maximum buffering delay in milliseconds before audio is flushed, used to control streaming latency vs. quality.  Defaults to `None`.
</ParamField>

<ParamField path="enable_word_timestamps" type="bool" default="False">
  When `True`, the response will include word-level start/end timing.  Defaults to `False`.
</ParamField>
