請求參數 | 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連結方式,不支援本地連結方式。
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連結方式,不支援本地連結方式。
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。 |