tts
Inworld AI Text-to-Speech Service Implementation.
Contains two TTS services: - InworldTTSService: WebSocket-based TTS service. - InworldHttpTTSService: HTTP-based TTS service.
Inworld’s text-to-speech (TTS) models offer ultra-realistic, context-aware speech synthesis and precise voice cloning capabilities, enabling developers to build natural and engaging experiences with human-like speech quality at an accessible price point.
- pipecat.services.inworld.tts.language_to_inworld_language(language: Language) str[source]
Convert a Language enum to an Inworld TTS BCP-47 language tag.
- Parameters:
language – The Language enum value to convert.
- Returns:
The corresponding Inworld BCP-47 language tag (e.g.
"en-US"). Unverified languages fall back to their BCP-47 string value with a warning.
- pipecat.services.inworld.tts.format_inworld_pronunciation(word: str, ipa: str) str | None[source]
Render a pronunciation as IPA between slashes, as Inworld reads it.
Inworld speaks the IPA wherever it appears inline, one word per pair of slashes, so a pronunciation covering several words cannot be written. Only English IPA symbols are read.
- Parameters:
word – The word being pronounced (unused: the IPA replaces it).
ipa – The pronunciation, in IPA.
- Returns:
The IPA wrapped in slashes, e.g.
/kriːt/, or None for an empty pronunciation or one spanning several words.
- class pipecat.services.inworld.tts.InworldTTSSettings(model: str | None | NotGiven = <factory>, extra: dict[str, ~typing.Any]=<factory>, voice: str | None | NotGiven = <factory>, language: Language | str | None | NotGiven = <factory>, speaking_rate: float | None | NotGiven = <factory>, temperature: float | None | NotGiven = <factory>, delivery_mode: Literal['STABLE', 'BALANCED', 'CREATIVE'] | None | ~pipecat.utils.types.NotGiven=<factory>, instruction: str | None | NotGiven = <factory>, enhance_generation: bool | None | NotGiven = <factory>)[source]
Bases:
TTSSettingsSettings for InworldTTSService and InworldHttpTTSService.
- Parameters:
speaking_rate – Speaking rate for speech synthesis.
temperature – Temperature for speech synthesis.
delivery_mode – Controls the stability vs. creativity tradeoff.
"STABLE"produces reliable, predictable speech."BALANCED"is the default midpoint."CREATIVE"produces more expressive, emotionally varied speech. Only supported byinworld-tts-2.instruction – Plain-English steering for the whole request, e.g.
"speak loudly and urgently". Honored byInworldHttpTTSServicewithinworld-tts-2; the WebSocket API takes steering as inline[tags]in the text instead, soInworldTTSServiceignores this field.enhance_generation – Whether to denoise the synthesized audio. Honored by
InworldHttpTTSService; the WebSocket API has no equivalent, soInworldTTSServiceignores this field.
- class pipecat.services.inworld.tts.InworldHttpTTSService(*, api_key: str, aiohttp_session: ClientSession, voice_id: str | None = None, model: str | None = None, streaming: bool = True, sample_rate: int | None = None, encoding: str = 'PCM', timestamp_transport_strategy: Literal['ASYNC', 'SYNC'] | None = 'ASYNC', params: InputParams | None = None, settings: InworldTTSSettings | None = None, **kwargs)[source]
Bases:
TTSServiceInworld AI HTTP-based TTS service.
Supports both streaming and non-streaming modes via the streaming parameter. Outputs PCM audio at configurable sample rates with word-level timestamps.
- Settings
alias of
InworldTTSSettings
- class InputParams(*, temperature: float | None = None, speaking_rate: float | None = None, timestamp_transport_strategy: Literal['ASYNC', 'SYNC'] | None = 'ASYNC')[source]
Bases:
BaseModelInput parameters for Inworld TTS configuration.
Deprecated since version 0.0.105: Use
InworldHttpTTSService.Settingsdirectly via thesettingsparameter instead. Will be removed in 2.0.0.- Parameters:
temperature – Temperature for speech synthesis.
speaking_rate – Speaking rate for speech synthesis.
timestamp_transport_strategy – The strategy to use for timestamp transport.
- __init__(*, api_key: str, aiohttp_session: ClientSession, voice_id: str | None = None, model: str | None = None, streaming: bool = True, sample_rate: int | None = None, encoding: str = 'PCM', timestamp_transport_strategy: Literal['ASYNC', 'SYNC'] | None = 'ASYNC', params: InputParams | None = None, settings: InworldTTSSettings | None = None, **kwargs)[source]
Initialize the Inworld TTS service.
- Parameters:
api_key – Inworld API key.
aiohttp_session – aiohttp ClientSession for HTTP requests.
voice_id –
ID of the voice to use for synthesis.
Deprecated since version 0.0.105: Use
settings=InworldHttpTTSService.Settings(voice=...)instead. Will be removed in 2.0.0.model –
ID of the model to use for synthesis.
Deprecated since version 0.0.105: Use
settings=InworldHttpTTSService.Settings(model=...)instead. Will be removed in 2.0.0.streaming – Whether to use streaming mode.
sample_rate – Audio sample rate in Hz.
encoding – Audio encoding format.
timestamp_transport_strategy – Strategy for timestamp transport (“ASYNC” or “SYNC”). Defaults to “ASYNC”.
params –
Input parameters for Inworld TTS configuration.
Deprecated since version 0.0.105: Use
settings=InworldHttpTTSService.Settings(...)instead. Will be removed in 2.0.0.settings – Runtime-updatable settings. When provided alongside deprecated parameters,
settingsvalues take precedence.**kwargs – Additional arguments passed to the parent class.
- get_expression_adapter() BaseExpressionAdapter[source]
The adapter for the model: audio markup on TTS-2 models, otherwise none.
- Returns:
The expression adapter for the current model.
- classmethod format_pronunciation(word: str, ipa: str) str | None[source]
Render a pronunciation as IPA between slashes.
See
format_inworld_pronunciation().- Parameters:
word – The word being pronounced.
ipa – The pronunciation, in IPA.
- Returns:
The IPA wrapped in slashes, or None when the pronunciation cannot be used.
- can_generate_metrics() bool[source]
Check if this service can generate processing metrics.
- Returns:
True, as Inworld TTS service supports metrics generation.
- language_to_service_language(language: Language) str | None[source]
Convert a Language enum to Inworld language format.
- Parameters:
language – The language to convert.
- Returns:
The Inworld-specific BCP-47 language code, or None if not supported.
- async setup(setup: FrameProcessorSetup)[source]
Set up the service.
- Parameters:
setup – Configuration object containing setup parameters.
- async push_frame(frame: Frame, direction: FrameDirection = FrameDirection.DOWNSTREAM)[source]
Push a frame and handle state changes.
- Parameters:
frame – The frame to push.
direction – The direction to push the frame.
- class pipecat.services.inworld.tts.InworldTTSService(*, api_key: str, voice_id: str | None = None, model: str | None = None, url: str = 'wss://api.inworld.ai/tts/v1/voice:streamBidirectional', sample_rate: int | None = None, encoding: str = 'PCM', auto_mode: bool | None = None, apply_text_normalization: str | None = None, timestamp_transport_strategy: Literal['ASYNC', 'SYNC'] | None = 'ASYNC', max_buffer_delay_ms: int | None = None, buffer_char_threshold: int | None = None, params: InputParams | None = None, settings: InworldTTSSettings | None = None, aggregate_sentences: bool | None = None, text_aggregation_mode: TextAggregationMode | None = None, append_trailing_space: bool = True, **kwargs: Any)[source]
Bases:
WebsocketTTSServiceInworld AI WebSocket-based TTS service.
Uses bidirectional WebSocket for lower latency streaming. Supports multiple independent audio contexts per connection (max 5). Outputs PCM audio with word-level timestamps.
- Settings
alias of
InworldTTSSettings
- class InputParams(*, temperature: float | None = None, speaking_rate: float | None = None, apply_text_normalization: str | None = None, max_buffer_delay_ms: int | None = None, buffer_char_threshold: int | None = None, auto_mode: bool | None = True, timestamp_transport_strategy: Literal['ASYNC', 'SYNC'] | None = 'ASYNC')[source]
Bases:
BaseModelInput parameters for Inworld WebSocket TTS configuration.
Deprecated since version 0.0.105: Use
InworldTTSService.Settingsdirectly via thesettingsparameter instead. Will be removed in 2.0.0.- Parameters:
temperature – Temperature for speech synthesis.
speaking_rate – Speaking rate for speech synthesis.
apply_text_normalization – Whether to apply text normalization.
max_buffer_delay_ms – Maximum buffer delay in milliseconds. Use the
max_buffer_delay_msconstructor argument instead.buffer_char_threshold – Buffer character threshold. Use the
buffer_char_thresholdconstructor argument instead.auto_mode – Whether to use auto mode. Recommended when texts are sent in full sentences/phrases. When enabled, the server controls flushing of buffered text to achieve minimal latency while maintaining high quality audio output. If None (default), automatically set based on aggregate_sentences.
timestamp_transport_strategy – The strategy to use for timestamp transport.
- __init__(*, api_key: str, voice_id: str | None = None, model: str | None = None, url: str = 'wss://api.inworld.ai/tts/v1/voice:streamBidirectional', sample_rate: int | None = None, encoding: str = 'PCM', auto_mode: bool | None = None, apply_text_normalization: str | None = None, timestamp_transport_strategy: Literal['ASYNC', 'SYNC'] | None = 'ASYNC', max_buffer_delay_ms: int | None = None, buffer_char_threshold: int | None = None, params: InputParams | None = None, settings: InworldTTSSettings | None = None, aggregate_sentences: bool | None = None, text_aggregation_mode: TextAggregationMode | None = None, append_trailing_space: bool = True, **kwargs: Any)[source]
Initialize the Inworld WebSocket TTS service.
- Parameters:
api_key – Inworld API key.
voice_id –
ID of the voice to use for synthesis.
Deprecated since version 0.0.105: Use
settings=InworldTTSService.Settings(voice=...)instead. Will be removed in 2.0.0.model –
ID of the model to use for synthesis.
Deprecated since version 0.0.105: Use
settings=InworldTTSService.Settings(model=...)instead. Will be removed in 2.0.0.url – URL of the Inworld WebSocket API.
sample_rate – Audio sample rate in Hz.
encoding – Audio encoding format.
auto_mode – Whether to use auto mode. When enabled, the server controls flushing of buffered text. If None (default), automatically set based on
aggregate_sentences.apply_text_normalization – Whether to apply text normalization.
timestamp_transport_strategy – Strategy for timestamp transport (“ASYNC” or “SYNC”). Defaults to “ASYNC”.
max_buffer_delay_ms – Maximum time in milliseconds the server buffers text before synthesizing it when auto mode is off. If None (default), 3000 is used.
buffer_char_threshold – Number of buffered characters that triggers synthesis. With the
SENTENCE_BOUNDARYstrategy it also cuts sentences longer than it. If None (default), 250 is used, or Inworld’s default withSENTENCE_BOUNDARY.params –
Input parameters for Inworld WebSocket TTS configuration.
Deprecated since version 0.0.105: Use
settings=InworldTTSService.Settings(...)instead. Will be removed in 2.0.0.settings – Runtime-updatable settings. When provided alongside deprecated parameters,
settingsvalues take precedence.aggregate_sentences –
Deprecated. Use text_aggregation_mode instead.
Deprecated since version 0.0.104: Use
text_aggregation_modeinstead. Will be removed in 2.0.0.text_aggregation_mode – How to aggregate text before synthesis. With
TextAggregationMode.TOKEN, auto mode and aninworld-tts-2model, tokens are streamed as they arrive and the server splits them at sentence boundaries.append_trailing_space – Whether to append a trailing space to text before sending to TTS.
**kwargs – Additional arguments passed to the parent class.
- get_expression_adapter() BaseExpressionAdapter[source]
The adapter for the model: audio markup on TTS-2 models, otherwise none.
- Returns:
The expression adapter for the current model.
- classmethod format_pronunciation(word: str, ipa: str) str | None[source]
Render a pronunciation as IPA between slashes.
See
format_inworld_pronunciation().- Parameters:
word – The word being pronounced.
ipa – The pronunciation, in IPA.
- Returns:
The IPA wrapped in slashes, or None when the pronunciation cannot be used.
- can_generate_metrics() bool[source]
Check if this service can generate processing metrics.
- Returns:
True, as Inworld WebSocket TTS service supports metrics generation.
- language_to_service_language(language: Language) str | None[source]
Convert a Language enum to Inworld language format.
- Parameters:
language – The language to convert.
- Returns:
The Inworld-specific BCP-47 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 flush_audio(context_id: str | None = None)[source]
Flush any pending audio without closing the context.
This triggers synthesis of all accumulated text in the buffer while keeping the context open for subsequent text. The context is only closed on interruption, disconnect, or end of session.
- async on_turn_context_completed()[source]
Close the server-side context at end of turn.
Sends close_context so contextClosed arrives immediately after the last audio byte.
- async on_audio_context_interrupted(context_id: str)[source]
Callback invoked when an audio context has been interrupted.
- async run_tts(text: str, context_id: str) AsyncGenerator[Frame | None, None][source]
Generate TTS audio for the given text using the Inworld WebSocket TTS service.
- Parameters:
text – The text to generate TTS audio for.
context_id – Unique identifier for this TTS context.
- Returns:
An asynchronous generator of frames.