tts_base
Shared foundation for the ElevenLabs multi-context WebSocket TTS services.
Holds what the text-to-speech and Text-to-Dialogue services have in common: the connection and task lifecycle, settings-change dispatch, the word-timestamp clock, and the shape of a synthesis request. Each service supplies its own endpoint URL and wire protocol.
- pipecat.services.elevenlabs.tts_base.ELEVENLABS_V2_5_LANGUAGES: frozenset[str] = frozenset({'ar', 'bg', 'cs', 'da', 'de', 'el', 'en', 'es', 'fi', 'fil', 'fr', 'hi', 'hr', 'hu', 'id', 'it', 'ja', 'ko', 'ms', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sv', 'ta', 'tr', 'uk', 'vi', 'zh'})
Languages the Flash and Turbo v2.5 models accept as a
language_code.
- pipecat.services.elevenlabs.tts_base.ELEVENLABS_V3_LANGUAGES: frozenset[str] = frozenset({'af', 'ar', 'as', 'az', 'be', 'bg', 'bn', 'bs', 'ca', 'ceb', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'et', 'fa', 'fi', 'fil', 'fr', 'ga', 'gl', 'gu', 'ha', 'he', 'hi', 'hr', 'hu', 'hy', 'id', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'kn', 'ko', 'ky', 'lb', 'ln', 'lt', 'lv', 'mk', 'ml', 'mr', 'ms', 'ne', 'nl', 'no', 'ny', 'pa', 'pl', 'ps', 'pt', 'ro', 'ru', 'sd', 'sk', 'sl', 'so', 'sr', 'sv', 'sw', 'ta', 'te', 'th', 'tr', 'uk', 'ur', 'vi', 'zh'})
Languages the Eleven v3 models accept as a
language_code. A superset ofELEVENLABS_V2_5_LANGUAGES.
- pipecat.services.elevenlabs.tts_base.ELEVENLABS_V4_LANGUAGES: frozenset[str] = frozenset({'af', 'ar', 'as', 'ast', 'az', 'be', 'bg', 'bn', 'bs', 'ca', 'ceb', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'et', 'fa', 'fi', 'fil', 'fr', 'ga', 'gl', 'gu', 'ha', 'he', 'hi', 'hr', 'hu', 'hy', 'id', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'kn', 'ko', 'ky', 'lb', 'ln', 'lt', 'lv', 'mi', 'mk', 'ml', 'mn', 'mr', 'ms', 'mt', 'my', 'ne', 'nl', 'no', 'ny', 'oc', 'or', 'pa', 'pl', 'ps', 'pt', 'ro', 'ru', 'sd', 'sk', 'sl', 'so', 'sr', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'tr', 'uk', 'ur', 'uz', 'vi', 'yue', 'zh'})
Languages the Eleven v4 models accept as a
language_code. A superset ofELEVENLABS_V3_LANGUAGES. This is the set the API accepts, which differs from the list ElevenLabs publishes for the models.
- pipecat.services.elevenlabs.tts_base.ELEVENLABS_MODEL_LANGUAGES: dict[str, frozenset[str]] = {'eleven_flash_v2_5': frozenset({'ar', 'bg', 'cs', 'da', 'de', 'el', 'en', 'es', 'fi', 'fil', 'fr', 'hi', 'hr', 'hu', 'id', 'it', 'ja', 'ko', 'ms', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sv', 'ta', 'tr', 'uk', 'vi', 'zh'}), 'eleven_turbo_v2_5': frozenset({'ar', 'bg', 'cs', 'da', 'de', 'el', 'en', 'es', 'fi', 'fil', 'fr', 'hi', 'hr', 'hu', 'id', 'it', 'ja', 'ko', 'ms', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sv', 'ta', 'tr', 'uk', 'vi', 'zh'}), 'eleven_v3': frozenset({'af', 'ar', 'as', 'az', 'be', 'bg', 'bn', 'bs', 'ca', 'ceb', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'et', 'fa', 'fi', 'fil', 'fr', 'ga', 'gl', 'gu', 'ha', 'he', 'hi', 'hr', 'hu', 'hy', 'id', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'kn', 'ko', 'ky', 'lb', 'ln', 'lt', 'lv', 'mk', 'ml', 'mr', 'ms', 'ne', 'nl', 'no', 'ny', 'pa', 'pl', 'ps', 'pt', 'ro', 'ru', 'sd', 'sk', 'sl', 'so', 'sr', 'sv', 'sw', 'ta', 'te', 'th', 'tr', 'uk', 'ur', 'vi', 'zh'}), 'eleven_v3_conversational': frozenset({'af', 'ar', 'as', 'az', 'be', 'bg', 'bn', 'bs', 'ca', 'ceb', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'et', 'fa', 'fi', 'fil', 'fr', 'ga', 'gl', 'gu', 'ha', 'he', 'hi', 'hr', 'hu', 'hy', 'id', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'kn', 'ko', 'ky', 'lb', 'ln', 'lt', 'lv', 'mk', 'ml', 'mr', 'ms', 'ne', 'nl', 'no', 'ny', 'pa', 'pl', 'ps', 'pt', 'ro', 'ru', 'sd', 'sk', 'sl', 'so', 'sr', 'sv', 'sw', 'ta', 'te', 'th', 'tr', 'uk', 'ur', 'vi', 'zh'}), 'eleven_v4': frozenset({'af', 'ar', 'as', 'ast', 'az', 'be', 'bg', 'bn', 'bs', 'ca', 'ceb', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'et', 'fa', 'fi', 'fil', 'fr', 'ga', 'gl', 'gu', 'ha', 'he', 'hi', 'hr', 'hu', 'hy', 'id', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'kn', 'ko', 'ky', 'lb', 'ln', 'lt', 'lv', 'mi', 'mk', 'ml', 'mn', 'mr', 'ms', 'mt', 'my', 'ne', 'nl', 'no', 'ny', 'oc', 'or', 'pa', 'pl', 'ps', 'pt', 'ro', 'ru', 'sd', 'sk', 'sl', 'so', 'sr', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'tr', 'uk', 'ur', 'uz', 'vi', 'yue', 'zh'}), 'eleven_v4_turbo': frozenset({'af', 'ar', 'as', 'ast', 'az', 'be', 'bg', 'bn', 'bs', 'ca', 'ceb', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'et', 'fa', 'fi', 'fil', 'fr', 'ga', 'gl', 'gu', 'ha', 'he', 'hi', 'hr', 'hu', 'hy', 'id', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'kn', 'ko', 'ky', 'lb', 'ln', 'lt', 'lv', 'mi', 'mk', 'ml', 'mn', 'mr', 'ms', 'mt', 'my', 'ne', 'nl', 'no', 'ny', 'oc', 'or', 'pa', 'pl', 'ps', 'pt', 'ro', 'ru', 'sd', 'sk', 'sl', 'so', 'sr', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'tr', 'uk', 'ur', 'uz', 'vi', 'yue', 'zh'})}
Models that accept a
language_code, and the languages each one takes. Sending a language a model doesn’t cover is rejected with a 400, so the language is checked against this mapping rather than only the model id.Models absent from the mapping take no language code at all. For
eleven_multilingual_v2that is deliberate: ElevenLabs documentslanguage_codeas unsupported for it, and omitting the key is how its auto-detection is meant to be used.
- pipecat.services.elevenlabs.tts_base.elevenlabs_language_code(model: str | None, language: str | None) str | None[source]
Resolve the
language_codeto send for a model.- Parameters:
model – The ElevenLabs model the request will use.
language – An ElevenLabs language code, or None to send none.
- Returns:
The language code to send, or None if it can’t be used - either because the model takes no language code or because it doesn’t cover this language. Both cases are logged.
- pipecat.services.elevenlabs.tts_base.language_to_elevenlabs_language(language: Language) str[source]
Convert a Language enum to ElevenLabs language code.
- Parameters:
language – The Language enum value to convert.
- Returns:
The corresponding service language code. If
languageis not in the verified mapping, falls back to the base language code (e.g.,enfromen-US) and logs a warning (viaresolve_language(..., use_base_code=True)).
- pipecat.services.elevenlabs.tts_base.output_format_from_sample_rate(sample_rate: int) str[source]
Get the appropriate output format string for a given sample rate.
- Parameters:
sample_rate – The audio sample rate in Hz.
- Returns:
The ElevenLabs output format string.
- pipecat.services.elevenlabs.tts_base.calculate_word_times(alignment_info: Mapping[str, Any], cumulative_time: float, partial_word: str = '', partial_word_start_time: float = 0.0, *, audio_tags: bool = False) tuple[list[tuple[str, float]], str, float][source]
Calculate word timestamps from character alignment information.
- Parameters:
alignment_info – Character alignment data from ElevenLabs API.
cumulative_time – Base time offset for this chunk.
partial_word – Partial word carried over from previous chunk.
partial_word_start_time – Start time of the partial word.
audio_tags – Whether a bracketed audio tag, such as
[short pause], is one word, spaces and all. Eleven v3 and v4 return the tags they perform in the alignment, and a tag reported whole matches the text it was sent in.
- Returns:
word_times: List of (word, timestamp) tuples for complete words
new_partial_word: Incomplete word at end of chunk (empty if chunk ends with space)
new_partial_word_start_time: Start time of the incomplete word
- Return type:
Tuple of (word_times, new_partial_word, new_partial_word_start_time)
- class pipecat.services.elevenlabs.tts_base.ElevenLabsTTSSettingsBase(model: str | None | NotGiven = <factory>, extra: dict[str, Any]=<factory>, voice: str | None | NotGiven = <factory>, language: Language | str | None | NotGiven = <factory>)[source]
Bases:
TTSSettingsSettings shared by the ElevenLabs WebSocket TTS services.
Carries the two declarative sets that
ElevenLabsTTSBase._update_settings()dispatches on. A service names the settings it can only change by reconnecting, and the settings it can change by opening a fresh context.
- class pipecat.services.elevenlabs.tts_base.ElevenLabsTTSBase(*, api_key: str, url: str, enable_logging: bool | None = None, **kwargs)[source]
Bases:
WebsocketTTSServiceShared behavior for the ElevenLabs multi-context WebSocket TTS services.
Owns the WebSocket connection and its receive and keepalive tasks, the settings-change dispatch, the word-timestamp clock, and the shape of a synthesis request. Subclasses supply the endpoint URL and the wire protocol: how text, keepalives, flushes and context closes are framed, and how server messages are read.
- Settings
alias of
ElevenLabsTTSSettingsBase
- __init__(*, api_key: str, url: str, enable_logging: bool | None = None, **kwargs)[source]
Initialize the ElevenLabs WebSocket TTS service.
- Parameters:
api_key – ElevenLabs API key for authentication.
url – Base WebSocket URL for the ElevenLabs API.
enable_logging – Whether to enable ElevenLabs server-side logging.
**kwargs – Additional arguments passed to the parent service.
- can_generate_metrics() bool[source]
Check if this service can generate processing metrics.
- Returns:
True, as ElevenLabs service supports metrics generation.
- language_to_service_language(language: Language) str | None[source]
Convert a Language enum to ElevenLabs language format.
- Parameters:
language – The language to convert.
- Returns:
The ElevenLabs-specific language code, or None if not supported.
- 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]
Close the ElevenLabs context when the bot is interrupted.
- async on_audio_context_completed(context_id: str)[source]
Reset alignment state after all audio for the context has played.
- async run_tts(text: str, context_id: str) AsyncGenerator[Frame | None, None][source]
Generate speech from text using ElevenLabs’ streaming WebSocket 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.