Skip to main content

Overview

Deepgram provides three TTS service implementations:
  • DeepgramTTSService for real-time streaming synthesis using Deepgram’s WebSocket API with support for interruptions and ultra-low latency
  • DeepgramHttpTTSService for batch synthesis using Deepgram’s HTTP API
  • DeepgramSageMakerTTSService for real-time synthesis using Deepgram TTS models deployed on AWS SageMaker endpoints via HTTP/2 bidirectional streaming

Installation

To use Deepgram TTS services, install the required dependencies:
pip install "pipecat-ai[deepgram]"
For the SageMaker variant, install the SageMaker dependencies instead:
pip install "pipecat-ai[sagemaker]"

Prerequisites

Deepgram Account Setup

Before using DeepgramTTSService or DeepgramHttpTTSService, you need:
  1. Deepgram Account: Sign up at Deepgram Console
  2. API Key: Generate an API key from your project dashboard
  3. Voice Selection: Choose from available Aura voice models

Required Environment Variables

  • DEEPGRAM_API_KEY: Your Deepgram API key for authentication

AWS SageMaker Setup

Before using DeepgramSageMakerTTSService, you need:
  1. AWS Account: With credentials configured (via environment variables, AWS CLI, or instance metadata)
  2. SageMaker Endpoint: A deployed SageMaker endpoint with a Deepgram TTS model
  3. Voice Selection: Choose from available Aura voice models

Configuration

DeepgramTTSService

api_key
str
required
Deepgram API key for authentication.
voice
str
default:"aura-2-helena-en"
Voice model to use for synthesis.
base_url
str
default:"wss://api.deepgram.com"
WebSocket base URL for Deepgram API.
sample_rate
int
default:"None"
Output audio sample rate in Hz. When None, uses the pipeline’s configured sample rate.
encoding
str
default:"linear16"
Audio encoding format. Must be one of: "linear16", "mulaw", "alaw".

DeepgramHttpTTSService

api_key
str
required
Deepgram API key for authentication.
voice
str
default:"aura-2-helena-en"
Voice model to use for synthesis.
aiohttp_session
aiohttp.ClientSession
required
An aiohttp session for HTTP requests. You must create and manage this yourself.
base_url
str
default:"https://api.deepgram.com"
HTTP API base URL.
sample_rate
int
default:"None"
Output audio sample rate in Hz.
encoding
str
default:"linear16"
Audio encoding format.

DeepgramSageMakerTTSService

endpoint_name
str
required
Name of the SageMaker endpoint with Deepgram TTS model deployed.
region
str
required
AWS region where the SageMaker endpoint is deployed (e.g., "us-east-2").
voice
str
default:"aura-2-helena-en"
Voice model to use for synthesis.
sample_rate
int
default:"None"
Output audio sample rate in Hz. When None, uses the pipeline’s configured sample rate.
encoding
str
default:"linear16"
Audio encoding format.

Usage

Basic Setup

from pipecat.services.deepgram import DeepgramTTSService

tts = DeepgramTTSService(
    api_key=os.getenv("DEEPGRAM_API_KEY"),
    voice="aura-2-helena-en",
)

HTTP Service

import aiohttp
from pipecat.services.deepgram import DeepgramHttpTTSService

async with aiohttp.ClientSession() as session:
    tts = DeepgramHttpTTSService(
        api_key=os.getenv("DEEPGRAM_API_KEY"),
        voice="aura-2-helena-en",
        aiohttp_session=session,
    )

SageMaker Service

from pipecat.services.deepgram.tts_sagemaker import DeepgramSageMakerTTSService

tts = DeepgramSageMakerTTSService(
    endpoint_name=os.getenv("SAGEMAKER_TTS_ENDPOINT_NAME"),
    region=os.getenv("AWS_REGION"),
    voice="aura-2-helena-en",
)

Notes

  • WebSocket vs HTTP vs SageMaker: The WebSocket service (DeepgramTTSService) and SageMaker service (DeepgramSageMakerTTSService) both support real-time streaming with interruption handling, making them suitable for interactive conversations. The HTTP service (DeepgramHttpTTSService) is simpler but processes each request as a batch.
  • Flush behavior: The WebSocket and SageMaker services automatically flush pending text when they receive an LLMFullResponseEndFrame or EndFrame, forcing Deepgram to generate audio for any remaining buffered text.
  • Encoding validation: The WebSocket service validates the encoding parameter at initialization and raises a ValueError for unsupported formats.
  • SageMaker deployment: The SageMaker service requires a Deepgram TTS model deployed to an AWS SageMaker endpoint. See the Deepgram SageMaker deployment guide for setup instructions.

Event Handlers

The WebSocket and SageMaker services support the standard service connection events:
EventDescription
on_connectedConnected to Deepgram (WebSocket or SageMaker)
on_disconnectedDisconnected from Deepgram
on_connection_errorConnection error occurred
@tts.event_handler("on_connected")
async def on_connected(service):
    print("Connected to Deepgram")