Skip to main content

Overview

HeyGenTTSService streams text to HeyGen Voice over a WebSocket and plays the audio as it arrives, with word-level timestamps so an interruption commits only the words actually spoken. HeyGenHttpTTSService streams raw PCM audio from HeyGen’s HTTP endpoint, one request per sentence, and also serves professional voice clones.

HeyGen TTS API Reference

Pipecat’s API methods for HeyGen TTS integration

Example Implementation

Complete example with the WebSocket service

HTTP Example

Complete example with the HTTP service

HeyGen Documentation

Official HeyGen Voice speech documentation

Installation

HeyGen TTS needs no extra dependencies. The heygen extra is only for the HeyGen video avatar.

Prerequisites

HeyGen Account Setup

Before using HeyGen TTS, you need:
  1. HeyGen Account: Sign up at HeyGen
  2. API Key: Generate an API key from your account
  3. Voice Selection: Choose a public voice ID, or use an instant or professional clone from your workspace

Required Environment Variables

  • HEYGEN_API_KEY: Your HeyGen API key for authentication

Configuration

HeyGenTTSService

str
required
HeyGen API key.
str
default:"wss://api.heygen.com"
HeyGen WebSocket base URL.
int | None
default:"None"
Output audio sample rate in Hz. When None, uses the pipeline’s sample rate.
bool | None
default:"None"
Whether <break time="1s" /> tags become pauses. Without it, HeyGen closes the WebSocket when the text contains a break tag.
bool | None
default:"None"
Whether HeyGen stores a copy of the audio and text. When None, HeyGen stores them.
str | None
default:"None"
Your identifier for the end user, recorded with HeyGen’s usage for attribution.
TextAggregationMode | None
default:"None"
How incoming text is aggregated before synthesis. TextAggregationMode.TOKEN streams LLM tokens as they arrive, and HeyGen generates at each sentence end.
HeyGenTTSService.Settings
default:"None"
Runtime-configurable settings. See Settings below.

Settings

Runtime-configurable settings passed via the settings constructor argument using HeyGenTTSService.Settings(...). These can be updated mid-conversation with TTSUpdateSettingsFrame; any change reconnects the WebSocket. See Service Settings for details.

HeyGenHttpTTSService

str
required
HeyGen API key.
aiohttp.ClientSession
required
Shared aiohttp session for HTTP requests.
str
default:"https://api.heygen.com"
HeyGen API base URL.
int | None
default:"None"
Output audio sample rate in Hz. When None, uses the pipeline’s sample rate.
HeyGenHttpTTSService.Settings
default:"None"
Runtime-configurable settings. See HTTP Settings below.

HTTP Settings

Passed via HeyGenHttpTTSService.Settings(...) and updatable with TTSUpdateSettingsFrame.

Usage

Basic Setup

Professional Voice Clones

Only HeyGenHttpTTSService serves professional voice clones, and they need the heygen-voice-1 model:

Notes

  • Chinese and Japanese: Set language on HeyGenTTSService to get per-character word timing. Without it, the service has no spaces to split words on, and the turn’s text frames arrive only when its audio ends.
  • Turbo Free: heygen-voice-1-turbo-free runs on shared capacity with no availability guarantee. When capacity is full, HeyGen refuses the turn and the service pushes an ErrorFrame. To keep the bot speaking, put a paid model behind it in a ServiceSwitcher with ServiceSwitcherStrategyFailover.

Event Handlers

HeyGenTTSService supports the standard service connection events: