Skip to main content

Overview

DeepgramTTSService provides high-quality text-to-speech synthesis using Deepgram’s Aura API with streaming capabilities and ultra-low latency. The service offers various voice models optimized for conversational AI applications with efficient audio streaming.

Installation

To use Deepgram services, install the required dependencies:
pip install "pipecat-ai[deepgram]"

Prerequisites

Deepgram Account Setup

Before using Deepgram TTS services, 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

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.

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,
    )

Notes

  • WebSocket vs HTTP: The WebSocket service (DeepgramTTSService) supports real-time streaming with interruption handling via the Clear message, making it suitable for interactive conversations. The HTTP service is simpler but processes each request as a batch.
  • Flush behavior: The WebSocket service automatically flushes pending text when it receives 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.

Event Handlers

Deepgram TTS supports the standard service connection events:
EventDescription
on_connectedConnected to Deepgram WebSocket
on_disconnectedDisconnected from Deepgram WebSocket
on_connection_errorWebSocket connection error occurred
@tts.event_handler("on_connected")
async def on_connected(service):
    print("Connected to Deepgram")