|
| 1 | +# HeyGen Avatar Plugin for Vision Agents |
| 2 | + |
| 3 | +Add realistic avatar video to your AI agents using HeyGen's streaming avatar API. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🎭 **Realistic Avatars**: Use HeyGen's high-quality avatars with natural movements |
| 8 | +- 🎤 **Automatic Lip-Sync**: Avatar automatically syncs with audio from any TTS provider |
| 9 | +- 🚀 **WebRTC Streaming**: Low-latency real-time video streaming via WebRTC |
| 10 | +- 🔌 **Easy Integration**: Works seamlessly with Vision Agents framework |
| 11 | +- 🎨 **Customizable**: Configure avatar, quality, resolution, and more |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +```bash |
| 16 | +pip install vision-agents-plugins-heygen |
| 17 | +``` |
| 18 | + |
| 19 | +Or with uv: |
| 20 | + |
| 21 | +```bash |
| 22 | +uv pip install vision-agents-plugins-heygen |
| 23 | +``` |
| 24 | + |
| 25 | +## Quick Start |
| 26 | + |
| 27 | +```python |
| 28 | +import asyncio |
| 29 | +from uuid import uuid4 |
| 30 | +from dotenv import load_dotenv |
| 31 | + |
| 32 | +from vision_agents.core import User, Agent |
| 33 | +from vision_agents.plugins import cartesia, deepgram, getstream, gemini, heygen |
| 34 | +from vision_agents.plugins.heygen import VideoQuality |
| 35 | + |
| 36 | +load_dotenv() |
| 37 | + |
| 38 | +async def start_avatar_agent(): |
| 39 | + agent = Agent( |
| 40 | + edge=getstream.Edge(), |
| 41 | + agent_user=User(name="AI Assistant with Avatar", id="agent"), |
| 42 | + instructions="You're a friendly AI assistant.", |
| 43 | + |
| 44 | + llm=gemini.LLM("gemini-2.0-flash"), |
| 45 | + tts=cartesia.TTS(), |
| 46 | + stt=deepgram.STT(), |
| 47 | + |
| 48 | + # Add HeyGen avatar |
| 49 | + processors=[ |
| 50 | + heygen.AvatarPublisher( |
| 51 | + avatar_id="default", |
| 52 | + quality=VideoQuality.HIGH |
| 53 | + ) |
| 54 | + ] |
| 55 | + ) |
| 56 | + |
| 57 | + call = agent.edge.client.video.call("default", str(uuid4())) |
| 58 | + |
| 59 | + with await agent.join(call): |
| 60 | + await agent.edge.open_demo(call) |
| 61 | + await agent.simple_response("Hello! I'm your AI assistant with an avatar.") |
| 62 | + await agent.finish() |
| 63 | + |
| 64 | +if __name__ == "__main__": |
| 65 | + asyncio.run(start_avatar_agent()) |
| 66 | +``` |
| 67 | + |
| 68 | +## Configuration |
| 69 | + |
| 70 | +### Environment Variables |
| 71 | + |
| 72 | +Set your HeyGen API key: |
| 73 | + |
| 74 | +```bash |
| 75 | +HEYGEN_API_KEY=your_heygen_api_key_here |
| 76 | +``` |
| 77 | + |
| 78 | +### AvatarPublisher Options |
| 79 | + |
| 80 | +```python |
| 81 | +from vision_agents.plugins.heygen import VideoQuality |
| 82 | + |
| 83 | +heygen.AvatarPublisher( |
| 84 | + avatar_id="default", # HeyGen avatar ID |
| 85 | + quality=VideoQuality.HIGH, # Video quality: VideoQuality.LOW, VideoQuality.MEDIUM, or VideoQuality.HIGH |
| 86 | + resolution=(1920, 1080), # Output resolution (width, height) |
| 87 | + api_key=None, # Optional: override env var |
| 88 | +) |
| 89 | +``` |
| 90 | + |
| 91 | +## Usage Examples |
| 92 | + |
| 93 | +### With Realtime LLM |
| 94 | + |
| 95 | +```python |
| 96 | +from vision_agents.plugins import gemini, heygen, getstream |
| 97 | + |
| 98 | +agent = Agent( |
| 99 | + edge=getstream.Edge(), |
| 100 | + agent_user=User(name="Realtime Avatar AI"), |
| 101 | + instructions="Be conversational and responsive.", |
| 102 | + |
| 103 | + llm=gemini.Realtime(fps=2), # No separate TTS needed |
| 104 | + |
| 105 | + processors=[ |
| 106 | + heygen.AvatarPublisher(avatar_id="professional_presenter") |
| 107 | + ] |
| 108 | +) |
| 109 | + |
| 110 | +call = agent.edge.client.video.call("default", str(uuid4())) |
| 111 | + |
| 112 | +with await agent.join(call): |
| 113 | + await agent.finish() |
| 114 | +``` |
| 115 | + |
| 116 | +### With Multiple Processors |
| 117 | + |
| 118 | +```python |
| 119 | +from vision_agents.plugins import ultralytics, heygen |
| 120 | + |
| 121 | +agent = Agent( |
| 122 | + edge=getstream.Edge(), |
| 123 | + agent_user=User(name="Fitness Coach"), |
| 124 | + instructions="Analyze user poses and provide feedback.", |
| 125 | + |
| 126 | + llm=gemini.Realtime(fps=3), |
| 127 | + |
| 128 | + processors=[ |
| 129 | + # Process incoming user video |
| 130 | + ultralytics.YOLOPoseProcessor(model_path="yolo11n-pose.pt"), |
| 131 | + # Publish avatar video |
| 132 | + heygen.AvatarPublisher(avatar_id="fitness_trainer") |
| 133 | + ] |
| 134 | +) |
| 135 | +``` |
| 136 | + |
| 137 | +## How It Works |
| 138 | + |
| 139 | +1. **Connection**: Establishes WebRTC connection to HeyGen's streaming API |
| 140 | +2. **Audio Input**: Receives audio from your TTS provider or Realtime LLM |
| 141 | +3. **Avatar Generation**: HeyGen generates avatar video with lip-sync |
| 142 | +4. **Video Streaming**: Streams avatar video to call participants via GetStream Edge |
| 143 | + |
| 144 | +## Requirements |
| 145 | + |
| 146 | +- Python 3.10+ |
| 147 | +- HeyGen API key (get one at [heygen.com](https://heygen.com)) |
| 148 | +- GetStream account for video calls |
| 149 | +- TTS provider (Cartesia, ElevenLabs, etc.) or Realtime LLM |
| 150 | + |
| 151 | +## Troubleshooting |
| 152 | + |
| 153 | +### Connection Issues |
| 154 | + |
| 155 | +If you experience connection problems: |
| 156 | + |
| 157 | +1. Check your HeyGen API key is valid |
| 158 | +2. Ensure you have network access to HeyGen's servers |
| 159 | +3. Check firewall settings for WebRTC traffic |
| 160 | + |
| 161 | +### Video Quality |
| 162 | + |
| 163 | +To optimize video quality: |
| 164 | + |
| 165 | +- Use `quality=VideoQuality.HIGH` for best results |
| 166 | +- Increase resolution if bandwidth allows |
| 167 | +- Ensure stable internet connection |
| 168 | + |
| 169 | +## API Reference |
| 170 | + |
| 171 | +### AvatarPublisher |
| 172 | + |
| 173 | +Main class for publishing HeyGen avatar video. |
| 174 | + |
| 175 | +**Methods:** |
| 176 | +- `publish_video_track()`: Returns video track for streaming |
| 177 | +- `state()`: Returns current state information |
| 178 | +- `close()`: Clean up resources |
| 179 | + |
| 180 | +## License |
| 181 | + |
| 182 | +MIT |
| 183 | + |
| 184 | +## Links |
| 185 | + |
| 186 | +- [Documentation](https://visionagents.ai/) |
| 187 | +- [GitHub](https://github.com/GetStream/Vision-Agents) |
| 188 | +- [HeyGen API Docs](https://docs.heygen.com/docs/streaming-api) |
| 189 | + |
0 commit comments