tts
Cartesia text-to-speech service implementations.
- class pipecat.services.cartesia.tts.GenerationConfig(*, volume: float | None = None, speed: float | None = None, emotion: str | None = None)[source]
Bases:
BaseModelConfiguration for Cartesia generation parameters.
Cartesia interprets these parameters as guidance to ensure natural speech. Test against your content for best results. Applicable to sonic-3 series models.
- Parameters:
volume – Volume multiplier for generated speech. Valid range: [0.5, 2.0]. Default is 1.0.
speed – Speed multiplier for generated speech. Valid range: [0.6, 1.5]. Default is 1.0.
emotion – Single emotion string to guide the emotional tone. Examples include neutral, angry, excited, content, sad, scared. Over 60 emotions are supported. For best results, use with recommended voices: Leo, Jace, Kyle, Gavin, Maya, Tessa, Dana, and Marian.
- pipecat.services.cartesia.tts.language_to_cartesia_language(language: Language) str[source]
Convert a Language enum to Cartesia language code.
- Parameters:
language – The Language enum value to convert.
- Returns:
The corresponding service language code. Regional codes Cartesia supports (e.g.,
es-MX) are kept. Any otherlanguagefalls back to the base language code (e.g.,defromde-CH) and logs a warning (viaresolve_language(..., use_base_code=True)).
- pipecat.services.cartesia.tts.format_cartesia_pronunciation(word: str, ipa: str) str | None[source]
Render a pronunciation as Cartesia inline phonemes.
Cartesia reads
<<…>>blocks of|-separated IPA phones, with stress marks directly before the vowel they stress. Each word of the IPA becomes its own block.- Parameters:
word – The word being pronounced (unused: the block replaces it).
ipa – The pronunciation, in IPA.
- Returns:
The inline phoneme blocks, e.g.
<<m|ɛ|t|f|ˈ|ɔ|ɹ|m|ɪ|n>>, or None for an empty pronunciation.
- class pipecat.services.cartesia.tts.CartesiaTTSSettings(model: str | None | NotGiven = <factory>, extra: dict[str, ~typing.Any]=<factory>, voice: str | None | NotGiven = <factory>, language: Language | str | None | NotGiven = <factory>, accent: str | None | NotGiven = <factory>, generation_config: GenerationConfig | None | NotGiven = <factory>, normalization: str | None | NotGiven = <factory>, pronunciation_dict_id: str | None | NotGiven = <factory>)[source]
Bases:
TTSSettingsSettings for CartesiaTTSService and CartesiaHttpTTSService.
- Parameters:
accent – Accent a multilingual voice speaks the language with (e.g.
british). The value must be one the voice itself supports, as listed in theaccentsfield of Cartesia’s Get Voice response. Unset lets Cartesia pick the closest accent the voice supports for the requested language.generation_config – Generation configuration for Cartesia models. Includes volume, speed (numeric), and emotion (string) parameters.
normalization – How Cartesia reads numbers, dates and phone numbers in the transcript.
"auto"(Cartesia’s default) follows the request’s language, and a language or locale code such as"en-GB"reads them in that convention whatever language is spoken."off"skips normalization and is only for text that is already spelled out: digits and symbols left in the text come out garbled or not at all. Word timestamps, and so the LLM context, carry the original text in every mode.pronunciation_dict_id –
The ID of the pronunciation dictionary to use for custom pronunciations.
Another way to guide pronunciation is to pass
replace_text()find-and-replace rules through thetext_transformsparameter. Pipecat applies them before the text reaches the provider, so the same rules can work across TTS services and depend less on what each provider supports. They’re worth trying if this setting isn’t giving you the results you want.
- class pipecat.services.cartesia.tts.CartesiaTTSService(*, api_key: str, voice_id: str | None = None, cartesia_version: str | None = None, url: str = 'wss://api.cartesia.ai/tts/websocket', model: str | None = None, sample_rate: int | None = None, encoding: str = 'pcm_s16le', container: str = 'raw', max_buffer_delay_ms: int | None = None, params: InputParams | None = None, extra_headers: dict[str, str] | None = None, settings: CartesiaTTSSettings | None = None, text_aggregation_mode: TextAggregationMode | None = None, aggregate_sentences: bool | None = None, **kwargs)[source]
Bases:
WebsocketTTSServiceCartesia TTS service with WebSocket streaming and word timestamps.
Provides text-to-speech using Cartesia’s streaming WebSocket API. Supports word-level timestamps, audio context management, and various voice customization options including generation configuration.
- Settings
alias of
CartesiaTTSSettings
- expression_adapter_class
alias of
CartesiaExpressionAdapter
- class InputParams(*, language: Language | None = Language.EN, generation_config: GenerationConfig | None = None, pronunciation_dict_id: str | None = None)[source]
Bases:
BaseModelInput parameters for Cartesia TTS configuration.
- Parameters:
language – Language to use for synthesis.
generation_config – Generation configuration for Cartesia models. Includes volume, speed (numeric), and emotion (string) parameters.
pronunciation_dict_id – The ID of the pronunciation dictionary to use for custom pronunciations.
- generation_config: GenerationConfig | None
- __init__(*, api_key: str, voice_id: str | None = None, cartesia_version: str | None = None, url: str = 'wss://api.cartesia.ai/tts/websocket', model: str | None = None, sample_rate: int | None = None, encoding: str = 'pcm_s16le', container: str = 'raw', max_buffer_delay_ms: int | None = None, params: InputParams | None = None, extra_headers: dict[str, str] | None = None, settings: CartesiaTTSSettings | None = None, text_aggregation_mode: TextAggregationMode | None = None, aggregate_sentences: bool | None = None, **kwargs)[source]
Initialize the Cartesia TTS service.
- Parameters:
api_key – Cartesia API key for authentication.
voice_id –
ID of the voice to use for synthesis.
Deprecated since version 0.0.105: Use
settings=CartesiaTTSService.Settings(voice=...)instead. Will be removed in 2.0.0.cartesia_version –
API version string for Cartesia service.
Deprecated since version 1.8.0: No replacement. The API version is pinned to the one this service implements. Will be removed in 2.0.0.
url – WebSocket URL for Cartesia TTS API.
model –
TTS model to use.
Deprecated since version 0.0.105: Use
settings=CartesiaTTSService.Settings(model=...)instead. Will be removed in 2.0.0.sample_rate – Audio sample rate. If None, uses default.
encoding – Audio encoding format.
container – Audio container format.
max_buffer_delay_ms – Server-side buffering window before generation starts.
0disables server buffering (custom buffering); any value in (0, 5000] enables managed buffering. IfNone, derived fromtext_aggregation_mode:0forSENTENCE(avoids stacking client and server buffering), unset forTOKEN(uses Cartesia’s 3000ms default).params –
Additional input parameters for voice customization.
Deprecated since version 0.0.105: Use
settings=CartesiaTTSService.Settings(...)instead. Will be removed in 2.0.0.extra_headers – Optional additional HTTP headers to send with the WebSocket handshake.
settings – Runtime-updatable settings. When provided alongside deprecated parameters,
settingsvalues take precedence.text_aggregation_mode – How to aggregate incoming text before synthesis.
aggregate_sentences –
Whether to aggregate sentences within the TTSService.
Deprecated since version 0.0.104: Use
text_aggregation_modeinstead. Will be removed in 2.0.0.**kwargs – Additional arguments passed to the parent service.
- classmethod format_pronunciation(word: str, ipa: str) str | None[source]
Render a pronunciation as Cartesia inline phonemes.
See
format_cartesia_pronunciation().- Parameters:
word – The word being pronounced.
ipa – The pronunciation, in IPA.
- Returns:
The inline phoneme blocks, or None when the pronunciation cannot be used.
- can_generate_metrics() bool[source]
Check if this service can generate processing metrics.
- Returns:
True, as Cartesia service supports metrics generation.
- language_to_service_language(language: Language) str | None[source]
Convert a Language enum to Cartesia language format.
- Parameters:
language – The language to convert.
- Returns:
The Cartesia-specific language code, or None if not supported.
- static EMOTION_TAG(emotion: CartesiaEmotion) str[source]
Convenience method to create an emotion tag.
- async setup(setup: FrameProcessorSetup)[source]
Set up the service and connect.
- Parameters:
setup – Configuration object containing setup parameters.
- async on_audio_context_interrupted(context_id: str)[source]
Cancel the active Cartesia context when the bot is interrupted.
- async on_audio_context_completed(context_id: str)[source]
Close the Cartesia context after all audio has been played.
No close message is needed: the server already considers the context done once it has sent its
donemessage, which is handled in_process_messages.
- async flush_audio(context_id: str | None = None)[source]
Flush any pending audio and finalize the current context.
- Parameters:
context_id – The specific context to flush. If None, falls back to the currently active context.
- async run_tts(text: str, context_id: str) AsyncGenerator[Frame | None, None][source]
Generate speech from text using Cartesia’s streaming API.
- Parameters:
text – The text to synthesize into speech.
context_id – The context ID for tracking audio frames.
- Yields:
Frame – Audio frames containing the synthesized speech.
- class pipecat.services.cartesia.tts.CartesiaHttpTTSService(*, api_key: str, voice_id: str | None = None, model: str | None = None, base_url: str = 'https://api.cartesia.ai', cartesia_version: str | None = None, aiohttp_session: ClientSession | None = None, sample_rate: int | None = None, encoding: str = 'pcm_s16le', container: str = 'raw', params: InputParams | None = None, extra_headers: dict[str, str] | None = None, settings: CartesiaTTSSettings | None = None, **kwargs)[source]
Bases:
TTSServiceCartesia HTTP-based TTS service.
Provides text-to-speech using Cartesia’s HTTP API for simpler, non-streaming synthesis. Suitable for use cases where streaming is not required and simpler integration is preferred.
- Settings
alias of
CartesiaTTSSettings
- expression_adapter_class
alias of
CartesiaExpressionAdapter
- class InputParams(*, language: Language | None = Language.EN, generation_config: GenerationConfig | None = None, pronunciation_dict_id: str | None = None)[source]
Bases:
BaseModelInput parameters for Cartesia HTTP TTS configuration.
- Parameters:
language – Language to use for synthesis.
generation_config – Generation configuration for Cartesia models. Includes volume, speed (numeric), and emotion (string) parameters.
pronunciation_dict_id – The ID of the pronunciation dictionary to use for custom pronunciations.
- generation_config: GenerationConfig | None
- __init__(*, api_key: str, voice_id: str | None = None, model: str | None = None, base_url: str = 'https://api.cartesia.ai', cartesia_version: str | None = None, aiohttp_session: ClientSession | None = None, sample_rate: int | None = None, encoding: str = 'pcm_s16le', container: str = 'raw', params: InputParams | None = None, extra_headers: dict[str, str] | None = None, settings: CartesiaTTSSettings | None = None, **kwargs)[source]
Initialize the Cartesia HTTP TTS service.
- Parameters:
api_key – Cartesia API key for authentication.
voice_id –
ID of the voice to use for synthesis.
Deprecated since version 0.0.105: Use
settings=CartesiaHttpTTSService.Settings(voice=...)instead. Will be removed in 2.0.0.model –
TTS model to use.
Deprecated since version 0.0.105: Use
settings=CartesiaHttpTTSService.Settings(model=...)instead. Will be removed in 2.0.0.base_url – Base URL for Cartesia HTTP API.
cartesia_version –
API version string for Cartesia service.
Deprecated since version 1.8.0: No replacement. The API version is pinned to the one this service implements. Will be removed in 2.0.0.
aiohttp_session – Optional aiohttp ClientSession for HTTP requests. If not provided, a session will be created and managed internally.
sample_rate – Audio sample rate. If None, uses default.
encoding – Audio encoding format.
container – Audio container format.
params –
Additional input parameters for voice customization.
Deprecated since version 0.0.105: Use
settings=CartesiaHttpTTSService.Settings(...)instead. Will be removed in 2.0.0.extra_headers – Optional additional HTTP headers to send with each synthesis request.
settings – Runtime-updatable settings. When provided alongside deprecated parameters,
settingsvalues take precedence.**kwargs – Additional arguments passed to the parent TTSService.
- classmethod format_pronunciation(word: str, ipa: str) str | None[source]
Render a pronunciation as Cartesia inline phonemes.
See
format_cartesia_pronunciation().- Parameters:
word – The word being pronounced.
ipa – The pronunciation, in IPA.
- Returns:
The inline phoneme blocks, or None when the pronunciation cannot be used.
- can_generate_metrics() bool[source]
Check if this service can generate processing metrics.
- Returns:
True, as Cartesia HTTP service supports metrics generation.
- language_to_service_language(language: Language) str | None[source]
Convert a Language enum to Cartesia language format.
- Parameters:
language – The language to convert.
- Returns:
The Cartesia-specific language code, or None if not supported.
- async setup(setup: FrameProcessorSetup)[source]
Set up the service.
- Parameters:
setup – Configuration object containing setup parameters.
- async run_tts(text: str, context_id: str) AsyncGenerator[Frame | None, None][source]
Generate speech from text using Cartesia’s HTTP API.
- Parameters:
text – The text to synthesize into speech.
context_id – The context ID for tracking audio frames.
- Yields:
Frame – Audio frames containing the synthesized speech.