Usage guide
Setup, environment variables, and Python/JavaScript/Go usage examples.
CartesiaTTSModel
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 onsonic-3 and newer models.
Constructor
Cartesia API key for authentication. Falls back to the
CARTESIA_API_KEY environment variable when omitted.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.Alias for
voice provided for backward compatibility. Accepts the same str | list[float] values. Ignored when voice is set.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.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".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.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.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.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.ID of a Cartesia pronunciation dictionary for custom phoneme rules. Overrides
generation_config.pronunciation_dict_id when set. Defaults to None.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.When
True, includes per-word start/end timing in the streamed response. Overrides generation_config.enable_word_timestamps when set. Defaults to False.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.aclose
emit
The event to emit.
interrupt
off
The event the handler was registered for.
The handler to remove.
on
callback is omitted.
The event to listen for.
The handler to invoke when the event is emitted. If
None, a decorator is returned that registers the decorated function.The registered callback when
callback is provided, otherwise a decorator that registers and returns the function it wraps.on_first_audio_byte
A callable, optionally async, invoked with synthesis timing information when the first audio byte is emitted.
synthesize
The text to synthesize; coerced to a string if needed.
GenerationConfig
Per-request generation settings for CartesiaTTS. An alternative to supplying individual flat parameters directly toCartesiaTTS.__init__. When both a flat parameter and the
corresponding GenerationConfig field are set, the flat parameter
takes precedence.
Fields
Playback speed multiplier in the range
[0.6, 1.5]. 1.0 is normal speed. Defaults to None (provider default).Emotion tag applied to the synthesized voice. Primary options include
"neutral", "calm", "angry", "content", "sad", "scared". Defaults to None.Output volume multiplier in the range
[0.5, 2.0]. 1.0 is normal volume. Defaults to None.ID of a Cartesia pronunciation dictionary to apply custom phoneme rules. Defaults to
None.Maximum buffering delay in milliseconds before audio is flushed, used to control streaming latency vs. quality. Defaults to
None.When
True, the response will include word-level start/end timing. Defaults to False.