tts

Deepgram text-to-speech service implementation.

This module provides integration with Deepgram’s text-to-speech API for generating speech from text using various voice models.

class pipecat.services.deepgram.tts.DeepgramTTSSettings(model: str | None | NotGiven = <factory>, extra: dict[str, Any]=<factory>, voice: str | None | NotGiven = <factory>, language: Language | str | None | NotGiven = <factory>, speed: float | None | NotGiven = <factory>)[source]

Bases: TTSSettings

Settings for DeepgramTTSService and DeepgramHttpTTSService.

Parameters:

speed – Speech-rate multiplier, from 0.7 to 1.5. None leaves Aura at its default rate. Supported by the Aura-2 English and Spanish voices; Deepgram recommends staying at or above 0.9 for Spanish.

pipecat.services.deepgram.tts.format_deepgram_pronunciation(word: str, ipa: str) → str | None[source]

Render a pronunciation as a Deepgram inline pronunciation object.

Aura-2 reads an escaped JSON object anywhere in the text and speaks its pronounce value in place of its word. The word stays in the text and is what Deepgram bills for; the IPA is not billed. English and Spanish only. Stress marks go directly before the vowel they stress; Aura-2 warns about any other placement and falls back to a best-effort pronunciation.

Parameters:
  • word – The word being pronounced, kept as the object’s word.

  • ipa – The pronunciation, in IPA.

Returns:

The inline object, e.g. \{"word": "dupilumab", "pronounce": "duːpˈɪljuːmæb"\}, or None for an empty pronunciation or IPA longer than Deepgram accepts for the word.

class pipecat.services.deepgram.tts.DeepgramTTSService(*, api_key: str, voice: str | None = None, base_url: str = 'wss://api.deepgram.com', sample_rate: int | None = None, encoding: str = 'linear16', mip_opt_out: bool | None = None, settings: DeepgramTTSSettings | None = None, **kwargs)[source]

Bases: WebsocketTTSService

Deepgram WebSocket-based text-to-speech service.

Provides real-time text-to-speech synthesis using Deepgram’s WebSocket API. Supports streaming audio generation with interruption handling via the Clear message for conversational AI use cases.

Settings

alias of DeepgramTTSSettings

SUPPORTED_ENCODINGS = ('linear16', 'mulaw', 'alaw')
__init__(*, api_key: str, voice: str | None = None, base_url: str = 'wss://api.deepgram.com', sample_rate: int | None = None, encoding: str = 'linear16', mip_opt_out: bool | None = None, settings: DeepgramTTSSettings | None = None, **kwargs)[source]

Initialize the Deepgram WebSocket TTS service.

Parameters:
  • api_key – Deepgram API key for authentication.

  • voice –

    Voice model to use for synthesis.

    Deprecated since version 0.0.105: Use settings=DeepgramTTSService.Settings(voice=...) instead. Will be removed in 2.0.0.

  • base_url – WebSocket base URL for Deepgram API. Defaults to “wss://api.deepgram.com”.

  • sample_rate – Audio sample rate in Hz. If None, uses service default.

  • encoding – Audio encoding format. Defaults to “linear16”. Must be one of SUPPORTED_ENCODINGS.

  • mip_opt_out – Opt out of the Deepgram Model Improvement Program. See https://dpgr.am/deepgram-mip for pricing impacts before setting to True.

  • settings – Runtime-updatable settings. When provided alongside deprecated parameters, settings values take precedence.

  • **kwargs – Additional arguments passed to parent InterruptibleTTSService class.

Raises:

ValueError – If encoding is not in SUPPORTED_ENCODINGS.

classmethod format_pronunciation(word: str, ipa: str) → str | None[source]

Render a pronunciation as a Deepgram inline pronunciation object.

See format_deepgram_pronunciation().

Parameters:
  • word – The word being pronounced.

  • ipa – The pronunciation, in IPA.

Returns:

The inline object, or None when the pronunciation cannot be used.

can_generate_metrics() → bool[source]

Check if the service can generate metrics.

Returns:

True, as Deepgram WebSocket TTS service supports metrics generation.

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]

Send Clear message to Deepgram when an audio context is interrupted.

The Clear message will clear Deepgram’s internal text buffer and stop sending audio, allowing for a new response to be generated.

Parameters:

context_id – The ID of the audio context that was interrupted.

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

Flush any pending audio synthesis by sending Flush command.

This should be called when the LLM finishes a complete response to force generation of audio from Deepgram’s internal text buffer.

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

Generate speech from text using Deepgram’s WebSocket TTS 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, plus start/stop frames.

class pipecat.services.deepgram.tts.DeepgramHttpTTSService(*, api_key: str, voice: str | None = None, aiohttp_session: ClientSession, base_url: str = 'https://api.deepgram.com', sample_rate: int | None = None, encoding: str = 'linear16', mip_opt_out: bool | None = None, settings: DeepgramTTSSettings | None = None, **kwargs)[source]

Bases: TTSService

Deepgram HTTP text-to-speech service.

Provides text-to-speech synthesis using Deepgram’s HTTP TTS API. Supports various voice models and audio encoding formats with configurable sample rates and quality settings.

Settings

alias of DeepgramTTSSettings

__init__(*, api_key: str, voice: str | None = None, aiohttp_session: ClientSession, base_url: str = 'https://api.deepgram.com', sample_rate: int | None = None, encoding: str = 'linear16', mip_opt_out: bool | None = None, settings: DeepgramTTSSettings | None = None, **kwargs)[source]

Initialize the Deepgram TTS service.

Parameters:
  • api_key – Deepgram API key for authentication.

  • voice –

    Voice model to use for synthesis.

    Deprecated since version 0.0.105: Use settings=DeepgramHttpTTSService.Settings(voice=...) instead. Will be removed in 2.0.0.

  • aiohttp_session – Shared aiohttp session for HTTP requests with connection pooling.

  • base_url – Custom base URL for Deepgram API. Defaults to “https://api.deepgram.com”.

  • sample_rate – Audio sample rate in Hz. If None, uses service default.

  • encoding – Audio encoding format. Defaults to “linear16”.

  • mip_opt_out – Opt out of the Deepgram Model Improvement Program. See https://dpgr.am/deepgram-mip for pricing impacts before setting to True.

  • settings – Runtime-updatable settings. When provided alongside deprecated parameters, settings values take precedence.

  • **kwargs – Additional arguments passed to parent TTSService class.

classmethod format_pronunciation(word: str, ipa: str) → str | None[source]

Render a pronunciation as a Deepgram inline pronunciation object.

See format_deepgram_pronunciation().

Parameters:
  • word – The word being pronounced.

  • ipa – The pronunciation, in IPA.

Returns:

The inline object, or None when the pronunciation cannot be used.

can_generate_metrics() → bool[source]

Check if the service can generate metrics.

Returns:

True, as Deepgram TTS service supports metrics generation.

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

Generate speech from text using Deepgram’s TTS 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, plus start/stop frames.

async setup(setup: FrameProcessorSetup)

Set up the service.

Parameters:

setup – Configuration object containing setup parameters.