[ PROMPT_NODE_24870 ]
text-overlays
[ SKILL_DOCUMENTATION ]
# 文本覆盖层 (Text Overlays)
为您的 HeyGen 视频添加文本覆盖层,用于标题、字幕、下三分之一标题 (lower thirds) 以及其他屏幕文本元素。
## 基础文本覆盖
typescript
const videoConfig = {
video_inputs: [
{
character: {
type: "avatar",
avatar_id: "josh_lite3_20230714",
avatar_style: "normal",
},
voice: {
type: "text",
input_text: "Welcome to our presentation!",
voice_id: "1bd001e7e50f421d891986aad5158bc8",
},
background: {
type: "color",
value: "#1a1a2e",
},
},
],
// 文本覆盖配置(如果您的 API 层级支持)
// 注意:可用性因套餐而异
};
## 文本覆盖配置
文本覆盖通常支持以下属性:
typescript
interface TextOverlay {
text: string;
x: number; // X 轴位置(像素或百分比)
y: number; // Y 轴位置(像素或百分比)
width?: number; // 文本框宽度
height?: number; // 文本框高度
font_family?: string;
font_size?: number;
font_color?: string;
background_color?: string;
text_align?: "left" | "center" | "right";
duration?: {
start: number; // 开始时间(秒)
end: number; // 结束时间(秒)
};
}
## 文本定位
### 坐标系
- **原点**: 左上角 (0, 0)
- **X 轴**: 向右增加
- **Y 轴**: 向下增加
- **单位**: 通常为像素或视频尺寸的百分比
### 常用位置
对于 1920x1080 视频:
| 位置 | X | Y | 描述 |
|----------|---|---|-------------|
| 左上 | 50 | 50 | 左上角 |
| 中上 | 960 | 50 | 顶部居中 |
| 右上 | 1870 | 50 | 右上角 |
| 中心 | 960 | 540 | 正中心 |
| 左下 | 50 | 1030 | 左下三分之一处 |
| 中下 | 960 | 1030 | 底部居中三分之一处 |
### 位置辅助函数
typescript
interface Position {
x: number;
y: number;
}
function getTextPosition(
location: "top-left" | "top-center" | "top-right" | "center" | "bottom-left" | "bottom-center" | "bottom-right",
videoWidth: number,
videoHeight: number,
padding: number = 50
): Position {
const positions: Record = {
"top-left": { x: padding, y: padding },
"top-center": { x: videoWidth / 2, y: padding },
"top-right": { x: videoWidth - padding, y: padding },
"center": { x: videoWidth / 2, y: videoHeight / 2 },
"bottom-left": { x: padding, y: vi