tts

Bland text-to-speech service implementations.

See https://docs.bland.ai/api-v2/post/tts-ws for the realtime WebSocket API and https://docs.bland.ai/api-v2/post/tts for the HTTP API.

class pipecat.services.bland.tts.BlandTTSSettings(model: str | None | NotGiven = <factory>, extra: dict[str, Any]=<factory>, voice: str | None | NotGiven = <factory>, language: Language | str | None | NotGiven = <factory>, expressiveness: float | None | NotGiven = <factory>, stability: float | None | NotGiven = <factory>, auto_formatting: bool | None | NotGiven = <factory>)[source]

Bases: TTSSettings

Settings for the Bland TTS services.

Parameters:
  • expressiveness – 0.0-1.0. Higher values produce more varied intonation.

  • stability – 0.0-1.0. Higher values produce more consistent delivery.

  • auto_formatting – Rewrite numbers into the form the voice reads best before synthesis. Phone numbers and SSNs, spelled out (“seven three two…”) or written as bare digits (“7327412065”), are read digit by digit in groups. Off unless set.

class pipecat.services.bland.tts.BlandTTSService(*, api_key: str, url: str = 'wss://api.bland.ai/v2/tts/ws', sample_rate: int | None = None, text_aggregation_mode: TextAggregationMode = TextAggregationMode.TOKEN, settings: BlandTTSSettings | None = None, **kwargs)[source]

Bases: WebsocketTTSService

Bland realtime WebSocket text-to-speech service.

Streams speech from Bland’s /v2/tts/ws endpoint over a single connection for the whole conversation. LLM tokens are forwarded as they arrive and Bland buffers them server-side, choosing its own synthesis boundaries, so no sentence tokenizer or character threshold is needed. Pass text_aggregation_mode=TextAggregationMode.SENTENCE to aggregate into sentences before sending instead.

Interruptions send Bland’s cancel message, so barge-in does not tear down the connection.

The voice sets the model; expressiveness and stability are calibrated for BTTS_V3.

Event handlers:

  • on_connected: Called when the websocket connection is established.

  • on_disconnected: Called when the websocket connection is closed.

  • on_connection_error: Called when a websocket connection error occurs.

Example:

tts = BlandTTSService(
    api_key=os.getenv("BLAND_API_KEY"),
    settings=BlandTTSService.Settings(
        voice="29158307-9893-4149-8a75-bc9ce313d64e"
    ),
)
Settings

alias of BlandTTSSettings

__init__(*, api_key: str, url: str = 'wss://api.bland.ai/v2/tts/ws', sample_rate: int | None = None, text_aggregation_mode: TextAggregationMode = TextAggregationMode.TOKEN, settings: BlandTTSSettings | None = None, **kwargs)[source]

Initialize the Bland WebSocket TTS service.

Parameters:
  • api_key – Bland API key for authentication.

  • url – WebSocket URL for the Bland realtime TTS API. Defaults to wss://api.bland.ai/v2/tts/ws.

  • sample_rate – Output sample rate in Hz. If None, uses the pipeline default. A rate Bland does not render is replaced with 48000, and the audio is resampled to this rate.

  • text_aggregation_mode – How to aggregate incoming text before sending. Defaults to TextAggregationMode.TOKEN, streaming LLM tokens straight to Bland for the lowest latency.

  • settings – Runtime-updatable settings.

  • **kwargs – Additional arguments passed to WebsocketTTSService.

can_generate_metrics() → bool[source]

Check if this service can generate processing metrics.

Returns:

True, as the Bland service supports metrics generation.

async setup(setup: FrameProcessorSetup)[source]

Set up the service and open the Bland session.

Parameters:

setup – Configuration object containing setup parameters.

async on_audio_context_interrupted(context_id: str)[source]

Cancel the interrupted turn instead of dropping the connection.

async flush_audio(context_id: str | None = None)[source]

End the active turn so Bland synthesizes its remaining buffered text.

Parameters:

context_id – The turn to end. Falls back to the active context.

async run_tts(text: str, context_id: str) → AsyncGenerator[Frame | None, None][source]

Append a text delta to the current turn.

Parameters:
  • text – The text to synthesize into speech.

  • context_id – The context ID for tracking audio frames.

Yields:

Frame – Nothing directly; audio arrives on the receive task.

class pipecat.services.bland.tts.BlandHttpTTSService(*, api_key: str, base_url: str = 'https://api.bland.ai/v2', sample_rate: int | None = None, aiohttp_session: ClientSession | None = None, settings: BlandTTSSettings | None = None, **kwargs)[source]

Bases: TTSService

Bland HTTP text-to-speech service.

Generates speech with Bland’s /v2/tts endpoint, which takes the complete text in one request. Voice agents should prefer BlandTTSService, which streams text into a realtime session.

Settings

alias of BlandTTSSettings

__init__(*, api_key: str, base_url: str = 'https://api.bland.ai/v2', sample_rate: int | None = None, aiohttp_session: ClientSession | None = None, settings: BlandTTSSettings | None = None, **kwargs)[source]

Initialize the Bland HTTP TTS service.

Parameters:
  • api_key – Bland API key for authentication.

  • base_url – Base URL for the Bland API. Defaults to https://api.bland.ai/v2.

  • sample_rate – Output sample rate in Hz. If None, uses the pipeline default.

  • aiohttp_session – Optional shared aiohttp session. When omitted, the service creates and owns one.

  • settings – Runtime-updatable settings.

  • **kwargs – Additional arguments passed to TTSService.

can_generate_metrics() → bool[source]

Check if this service can generate processing metrics.

Returns:

True, as the Bland service supports metrics generation.

async setup(setup: FrameProcessorSetup)[source]

Set up the service, creating an aiohttp session if one was not provided.

Parameters:

setup – Configuration object containing setup parameters.

async stop(frame)[source]

Stop the service and release an owned aiohttp session.

async cancel(frame)[source]

Cancel the service and release an owned aiohttp session.

async cleanup()[source]

Release Bland TTS resources at teardown.

async run_tts(text: str, context_id: str) → AsyncGenerator[Frame | None, None][source]

Generate speech from text using Bland’s /v2/tts endpoint.

Parameters:
  • text – The text to synthesize.

  • context_id – The context ID for tracking audio frames.

Yields:

Frame – Audio frames containing the synthesized speech.