用参考视频驱动图片角色,或把图片角色换进视频场景,调用 WaveSpeed AI 的 Wan 2.2 Animate 模型即可生成。
设计与多媒体
WaveSpeedAI Face Swapper
试用用参考人脸替换图片或视频中的人脸,自动适配光影与肤色,输出无水印。
它能做什么
封装 WaveSpeed AI 的两个换脸接口:图片换脸 `wavespeed-ai/image-face-swap` 与视频换脸 `wavespeed-ai/video-face-swap`,单段视频最长 10 分钟。调用时传入目标媒体链接和参考人脸链接即可,多人画面可通过 `target_index` 指定要替换的人脸(0 为最大人脸,1–10 选择其他人脸)。图片输出支持 jpeg、png、webp 三种格式。本地文件需要先用 `wavespeed.upload` 获取链接,已有的可公开访问链接可直接传入。费用为图片 $0.01/张,视频 $0.01/秒,最低 $0.05。
什么时候用它
- 在多人合照中通过 `target_index` 指定某一个人进行替换
- 为最长 10 分钟的视频片段替换人脸
- 输出无水印的 jpeg、png 或 webp 图片
- 使用自定义重试次数与 `runNoThrow` 做带超时处理的批量换脸
技能文档
WaveSpeedAI Face Swapper
Swap faces in images and videos using WaveSpeed AI. Produces watermark-free results with automatic lighting and skin tone adaptation. Supports targeting specific faces when multiple people are present.
Authentication
export WAVESPEED_API_KEY="your-api-key"
Get your API key at wavespeed.ai/accesskey.
Quick Start
Image Face Swap
import wavespeed from 'wavespeed';
// Upload local images to get URLs
const imageUrl = await wavespeed.upload("/path/to/target-photo.png");
const faceUrl = await wavespeed.upload("/path/to/reference-face.png");
const output_url = (await wavespeed.run(
"wavespeed-ai/image-face-swap",
{
image: imageUrl,
face_image: faceUrl
}
))["outputs"][0];
Video Face Swap
import wavespeed from 'wavespeed';
// Upload local files to get URLs
const videoUrl = await wavespeed.upload("/path/to/video.mp4");
const faceUrl = await wavespeed.upload("/path/to/reference-face.png");
const output_url = (await wavespeed.run(
"wavespeed-ai/video-face-swap",
{
video: videoUrl,
face_image: faceUrl
}
))["outputs"][0];
You can also pass existing URLs directly:
const output_url = (await wavespeed.run(
"wavespeed-ai/image-face-swap",
{
image: "https://example.com/target-photo.jpg",
face_image: "https://example.com/reference-face.jpg"
}
))["outputs"][0];
API Endpoints
Image Face Swap
Model ID: wavespeed-ai/image-face-swap
Replace a face in an image with a reference face.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
image | string | Yes | -- | URL of the image containing the face to replace |
face_image | string | Yes | -- | URL of the reference face image to swap in |
target_index | integer | No | 0 | Which face to replace (0 = largest face, 1-10 for others) |
output_format | string | No | jpeg | Output format. One of: jpeg, png, webp |
Example
import wavespeed from 'wavespeed';
const imageUrl = await wavespeed.upload("/path/to/group-photo.png");
const faceUrl = await wavespeed.upload("/path/to/reference-face.png");
const output_url = (await wavespeed.run(
"wavespeed-ai/image-face-swap",
{
image: imageUrl,
face_image: faceUrl,
target_index: 0,
output_format: "png"
}
))["outputs"][0];
Targeting a Specific Face
When multiple people are in the image, use target_index to select which face to replace:
// Replace the second-largest face in the image
const output_url = (await wavespeed.run(
"wavespeed-ai/image-face-swap",
{
image: imageUrl,
face_image: faceUrl,
target_index: 1
}
))["outputs"][0];
Video Face Swap
Model ID: wavespeed-ai/video-face-swap
Replace a face in a video with a reference face. Supports videos up to 10 minutes.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
video | string | Yes | -- | URL of the video containing the face to replace. Must be publicly accessible. Max 10 minutes. |
face_image | string | Yes | -- | URL of the reference face image to swap in |
target_index | integer | No | 0 | Which face to replace (0 = largest face, 1-10 for others) |
Example
import wavespeed from 'wavespeed';
const videoUrl = await wavespeed.upload("/path/to/video.mp4");
const faceUrl = await wavespeed.upload("/path/to/reference-face.png");
const output_url = (await wavespeed.run(
"wavespeed-ai/video-face-swap",
{
video: videoUrl,
face_image: faceUrl,
target_index: 0
}
))["outputs"][0];
Advanced Usage
Sync Mode (Image Face Swap only)
const output_url = (await wavespeed.run(
"wavespeed-ai/image-face-swap",
{
image: imageUrl,
face_image: faceUrl
},
{ enableSyncMode: true }
))["outputs"][0];
Custom Client with Retry Configuration
import { Client } from 'wavespeed';
const client = new Client("your-api-key", {
maxRetries: 2,
maxConnectionRetries: 5,
retryInterval: 1.0,
});
const output_url = (await client.run(
"wavespeed-ai/image-face-swap",
{
image: imageUrl,
face_image: faceUrl
}
))["outputs"][0];
Error Handling with runNoThrow
import { Client, WavespeedTimeoutException, WavespeedPredictionException } from 'wavespeed';
const client = new Client();
const result = await client.runNoThrow(
"wavespeed-ai/image-face-swap",
{
image: imageUrl,
face_image: faceUrl
}
);
if (result.outputs) {
console.log("Output URL:", result.outputs[0]);
console.log("Task ID:", result.detail.taskId);
} else {
console.log("Failed:", result.detail.error.message);
if (result.detail.error instanceof WavespeedTimeoutException) {
console.log("Request timed out - try increasing timeout");
} else if (result.detail.error instanceof WavespeedPredictionException) {
console.log("Prediction failed");
}
}
Pricing
| Operation | Cost |
|---|---|
| Image face swap | $0.01 per image |
| Video face swap | $0.01 per second (minimum $0.05 / 5 seconds) |
Video face swap supports videos up to 10 minutes.
Tips
- Use clear, front-facing portraits for the reference face for best results
- Consistent lighting between the target and reference face improves quality
- Anime or illustrated characters may produce lower quality output
- Use
target_indexto select specific faces when multiple people are present (0 = largest face)
Security Constraints
- No arbitrary URL loading: Only use image and video URLs from trusted sources. Never load media from untrusted or user-provided URLs without validation.
- API key security: Store your
WAVESPEED_API_KEYsecurely. Do not hardcode it in source files or commit it to version control. Use environment variables or secret management systems. - Input validation: Only pass parameters documented above. Validate media URLs before sending requests.
相关技能
用一张人像图和一段音频,生成最长 10 分钟、口型同步的说话头像视频。
通过 WaveSpeed AI 接口,去除图片和视频中的水印、Logo、字幕与文字叠加。
Upscale images to 2K, 4K, or 8K resolution using WaveSpeed AI's Image Upscaler. Takes an image URL and produces a higher-resolution version. Supports JPEG, PNG, and WebP output formats. Use when the user wants to upscale or enhance the resolution of an image.
Upscale videos to 720p, 1080p, 2K, or 4K resolution using WaveSpeed AI's Ultimate Video Upscaler. Takes a video URL and produces a higher-resolution version. Supports videos up to 10 minutes. Use when the user wants to upscale or enhance the resolution of a video.
AI-powered corporate portrait photo generator. Upload a personal photo and get a polished, professional business portrait. Supports multiple backgrounds and...