请求参数 | curl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis' \
--header 'X-DashScope-Async: enable' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "emo-v1",
"input": {
"image_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251225/onmomb/emo.png",
"audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250825/aejgyj/input_audio.mp3",
"face_bbox":[302,286,610,593],
"ext_bbox":[71,9,840,778]
},
"parameters": {
"style_level": "normal"
}
}'
import requests
import os
# 1. 从环境变量获取 API Key
api_key = os.getenv("DASHSCOPE_API_KEY")
# 2. 准备请求信息
url = 'https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis'
headers = {
'X-DashScope-Async': 'enable',
'Authorization': f'Bearer {api_key}',
}
payload = {
"model": "emo-v1",
"input": {
"image_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251225/onmomb/emo.png",
"audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250825/aejgyj/input_audio.mp3",
"face_bbox": [302, 286, 610, 593],
"ext_bbox": [71, 9, 840, 778]
},
"parameters": {
"style_level": "normal"
}
}
# 3. 发送 POST 请求
# 使用 'json' 参数,requests会自动处理JSON序列化和'Content-Type'头
response = requests.post(url, headers=headers, json=payload)
# 4. 打印服务器返回的原始JSON响应
# 如果请求成功,会打印任务ID等信息。
# 如果请求失败,会打印服务器返回的错误信息。
print(response.json())
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;
/**
* 要求:
* - Java 8 或更高版本。
* - 运行时需要设置环境变量 DASHSCOPE_API_KEY。
**/
public class DashScopeApiDemo {
public static void main(String[] args) throws IOException {
// 1. 从环境变量获取 API Key
String apiKey = System.getenv("DASHSCOPE_API_KEY");
// 2. 准备请求信息
String urlString = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis";
String payload = "{"
+ "\"model\": \"emo-v1\","
+ "\"input\": {"
+ "\"image_url\": \"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251225/onmomb/emo.png\","
+ "\"audio_url\": \"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250825/aejgyj/input_audio.mp3\","
+ "\"face_bbox\": [302, 286, 610, 593],"
+ "\"ext_bbox\": [71, 9, 840, 778]"
+ "},"
+ "\"parameters\": {"
+ "\"style_level\": \"normal\""
+ "}"
+ "}";
// 3. 发送 POST 请求
URL url = new URL(urlString);
// noinspection StartSSRFNetHookCheckingInspection
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Authorization", "Bearer " + apiKey);
connection.setRequestProperty("X-DashScope-Async", "enable");
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
connection.setRequestProperty("Accept", "application/json");
connection.setDoOutput(true);
// 获取输出流并写入请求体数据
try (OutputStream os = connection.getOutputStream()) {
byte[] input = payload.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
// 4. 获取并打印服务器响应
int statusCode = connection.getResponseCode();
System.out.println("Status Code: " + statusCode);
// 根据状态码选择输入流(正常流或错误流)
InputStream inputStream = (statusCode >= 200 && statusCode < 300)
? connection.getInputStream()
: connection.getErrorStream();
String responseBody;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
responseBody = reader.lines().collect(Collectors.joining("\n"));
}
System.out.println("Response Body: " + responseBody);
connection.disconnect();
}
}
// 需要安装node-fetch包
// npm install node-fetch@2
// 导入 node-fetch 库
const fetch = require('node-fetch');
// 1. 从环境变量获取 API Key
const apiKey = process.env.DASHSCOPE_API_KEY;
// 2. 准备请求信息
const url = 'https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis';
const headers = {
'X-DashScope-Async': 'enable',
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json' // 使用 fetch 时需要手动指定
};
const payload = {
"model": "emo-v1",
"input": {
"image_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251225/onmomb/emo.png",
"audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250825/aejgyj/input_audio.mp3",
"face_bbox": [302, 286, 610, 593],
"ext_bbox": [71, 9, 840, 778]
},
"parameters": {
"style_level": "normal"
}
};
// 3. 发送 POST 请求并处理响应
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(payload) // 必须将 JS 对象转换为 JSON 字符串
})
.then(response => response.json()) // 将响应体解析为 JSON
.then(data => {
// 4. 打印服务器返回的 JSON 数据
console.log(data);
});
|
请求头(Headers) |
X-DashScope-Async string (必选) 异步处理配置参数。HTTP请求只支持异步,必须设置为enable。
重要 缺少此请求头将报错:“current user api does not support synchronous calls”。 |
Authorization string(必选) 请求身份认证。接口使用阿里云百炼API Key进行身份认证。示例值:Bearer sk-xxxx。 |
Content-Type string (必选) 请求内容类型。此参数必须设置为application/json。 |
请求体(Request Body) |
model string (必选) 模型名称。示例值:emo-v1。
说明 若调用独立部署模型,则填入部署成功的模型名称 |
input object (必选) 输入的基本信息。 属性 image_url string (必选) 用户上传的图片 URL。模型将根据EMO图像检测API返回的 ext_bbox 参数,对原始图片进行裁剪。裁剪后区域的宽高比直接决定了输出视频的画幅比例与分辨率。 若 ext_bbox 宽高比为1:1,则生成512×512的头像视频;若为3:4,则生成512×704的半身像视频。 图像要求最小边长 ≥ 400像素,最大边长 ≤ 7000像素。 格式支持:jpg,jpeg,png,bmp,webp。 示例值:https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250911/yhdvfg/emo.png。 上传文件支持HTTP或HTTPS链接方式,不支持本地链接方式。您也可在此获取临时公网URL。
audio_url string (必选) 用户上传的音频文件 URL, 用于EMO模型推理的输入。 需包含清晰人声,并尽可能去除环境噪音、背景音乐等干扰。 文件大小 ≤ 15 MB,时长 ≤ 60 s。 格式支持:wav、mp3。 示例值:https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250825/aejgyj/input_audio.mp3。 上传文件支持HTTP或HTTPS链接方式,不支持本地链接方式。您也可在此获取临时公网URL。
face_bbox array (必选) 图片中人脸区域bbox的像素坐标,应输入EMO图像检测API出参中同名字段的值。坐标格式[x1,y1,x2,y2],分别对应左上和右下两个点的坐标。示例值:[302,286,610,593]。 图像左上角为坐标原点(0,0),x轴向右为正,y轴向下为正。 ext_bbox array (必选) 图片中动态区域bbox的像素坐标,应输入EMO图像检测API出参中同名字段的值。该区域的宽高比为1:1或3:4。坐标格式[x1,y1,x2,y2],分别对应左上和右下两个点的坐标。示例值:[71,9,840,778]。 |
parameters object(可选) 属性 style_level string (可选)默认值:normal 可选择动作风格强度控制人物的运动姿态和幅度,当前支持3种:normal、calm、active,分别对应人物动作风格适中、平静、活泼。默认为normal。 |