[ PROMPT_NODE_24866 ]
streaming-avatars
[ SKILL_DOCUMENTATION ]
# 流式数字人 (Streaming Avatars)
HeyGen 的流式数字人功能支持实时交互式数字人体验,非常适合实时客户服务、虚拟助手和交互式应用。
## 概览
流式数字人提供:
- **实时渲染** - 数字人对输入做出即时响应
- **交互式对话** - 双向对话能力
- **WebRTC 流媒体** - 低延迟视频传输
- **会话管理** - 创建和管理实时会话
## 创建流式会话
### 请求字段
| 字段 | 类型 | 必填 | 描述 |
|-------|------|:---:|-------------|
| `avatar_id` | string | ✓ | 用于流式传输的数字人 ID |
| `voice_id` | string | ✓ | 用于 TTS 响应的语音 ID |
| `quality` | string | | `"low"`, `"medium"`, 或 `"high"` |
| `video_encoding` | string | | `"H264"` 或 `"VP8"` |
### curl
bash
curl -X POST "https://api.heygen.com/v1/streaming.new"
-H "X-Api-Key: $HEYGEN_API_KEY"
-H "Content-Type: application/json"
-d '{
"avatar_id": "josh_lite3_20230714",
"voice_id": "1bd001e7e50f421d891986aad5158bc8",
"quality": "high"
}'
### TypeScript
typescript
interface StreamingSessionRequest {
avatar_id: string; // 必填
voice_id: string; // 必填
quality?: "low" | "medium" | "high";
video_encoding?: "H264" | "VP8";
}
interface StreamingSessionResponse {
error: null | string;
data: {
session_id: string;
access_token: string;
url: string;
ice_servers: IceServer[];
};
}
interface IceServer {
urls: string[];
username?: string;
credential?: string;
}
async function createStreamingSession(
config: StreamingSessionRequest
): Promise {
const response = await fetch("https://api.heygen.com/v1/streaming.new", {
method: "POST",
headers: {
"X-Api-Key": process.env.HEYGEN_API_KEY!,
"Content-Type": "application/json",
},
body: JSON.stringify(config),
});
const json: StreamingSessionResponse = await response.json();
if (json.error) {
throw new Error(json.error);
}
return json.data;
}
### Python
python
import requests
import os
def create_streaming_session(config: dict) -> dict:
response = requests.post(
"https://api.heygen.com/v1/streaming.new",
headers={
"X-Api-Key": os.environ["HEYGEN_API_KEY"],
"Content-Type": "application/json"
},
json=config
)
data =