Features
- 🎤 Automatic Lip-Sync: Avatar automatically syncs with audio
- 🚀 WebRTC Streaming: Low-latency real-time video streaming
- 🎨 Customizable: Change avatar, quality, and resolution
Installation
Install the Stream HeyGen plugin withExample
Check out our HeyGen examples to see working code samples using the plugin, or read on for some key details.Initialisation
The HeyGen plugin for Stream exists in the form of theAvatarPublisher class:
To initialise without passing in the API key, make sure the
HEYGEN_API_KEY is available as an environment variable.
You can do this either by defining it in a .env file or exporting it directly in your terminal.Parameters
These are the parameters available in the HeyGen AvatarPublisher plugin for you to customise:| Name | Type | Default | Description |
|---|---|---|---|
avatar_id | str | "default" | HeyGen avatar ID to use for streaming. Get this from your HeyGen dashboard. |
quality | VideoQuality | VideoQuality.HIGH | Video quality setting. Options: VideoQuality.LOW, VideoQuality.MEDIUM, or VideoQuality.HIGH. |
resolution | Tuple[int, int] | (1920, 1080) | Output video resolution as (width, height). |
api_key | str or None | None | Your HeyGen API key. If not provided, the plugin will look for the HEYGEN_API_KEY environment variable. |
How It Works
The HeyGen avatar integration works differently depending on whether you’re using a standard streaming LLM or a Realtime LLM:With Streaming LLMs (Recommended for Lower Latency)
When using a standard streaming LLM (like Gemini LLM), the flow is:- Text Generation: Your LLM generates text responses
- Lip-Sync: Text is sent directly to HeyGen for avatar lip-sync generation
- Audio Synthesis: HeyGen generates both the avatar video and audio with TTS
- Streaming: Avatar video and audio are streamed to call participants
With Realtime LLMs
When using a Realtime LLM (like Gemini Realtime), the flow is:- Audio Generation: Realtime LLM generates audio directly
- Transcription: Audio is transcribed to text
- Lip-Sync: Text transcription is sent to HeyGen for avatar lip-sync
- Video Only: HeyGen generates avatar video (audio comes from the Realtime LLM)
- Streaming: Avatar video and LLM audio are streamed together
Usage in Agent
Add theAvatarPublisher to your agent’s processors list:
Video Quality Options
Choose the appropriate quality based on your bandwidth and requirements:VideoQuality.LOW: Lower bandwidth usage, suitable for slower connectionsVideoQuality.MEDIUM: Balanced quality and bandwidthVideoQuality.HIGH: Best quality, requires stable high-bandwidth connection
Getting Your Avatar ID
- Sign up for a HeyGen account
- Navigate to your HeyGen dashboard
- Find your avatar ID in the avatar settings
- Use this ID in the
avatar_idparameter
Troubleshooting
Connection Issues
If you experience connection problems:- Verify your HeyGen API key is valid
- Ensure network access to HeyGen’s servers
- Check firewall settings for WebRTC traffic
Video Quality Issues
To optimize video quality:- Use
quality=VideoQuality.HIGHfor best results - Ensure stable internet connection
- Consider lowering resolution if bandwidth is limited
No Avatar Appearing
- Check browser console for errors
- Verify Stream credentials are correct
- Ensure HeyGen API key has proper permissions

