main
HuangHai 2 months ago
parent 497adf10c3
commit 7d9d75004a

@ -34,10 +34,10 @@ public class DsEmoVideoSynthesis {
/**
* EMOAPI
*
* @param imageUrl URL
* @param audioUrl URL
* @param faceBbox [x, y, width, height]
* @param extBbox [x, y, width, height]
* @param imageUrl URL
* @param audioUrl URL
* @param faceBbox [x, y, width, height]
* @param extBbox [x, y, width, height]
* @param styleLevel normal, strong
* @return ID
* @throws Exception
@ -96,14 +96,14 @@ public class DsEmoVideoSynthesis {
log.info("EMO视频合成响应: {}", responseBody);
JSONObject responseJson = JSON.parseObject(responseBody);
// 获取任务ID
String taskId = responseJson.getJSONObject("output").getString("task_id");
log.info("EMO视频合成任务ID: {}", taskId);
return taskId;
}
/**
*
*
@ -121,7 +121,7 @@ public class DsEmoVideoSynthesis {
// 创建请求
Request request = new Request.Builder()
.url(API_URL + taskId)
.url("https://dashscope.aliyuncs.com/api/v1/tasks/" + taskId)
.method("GET", null)
.addHeader("Authorization", "Bearer " + API_KEY)
.build();
@ -143,7 +143,7 @@ public class DsEmoVideoSynthesis {
return JSON.parseObject(responseBody);
}
/**
*
*
@ -206,7 +206,7 @@ public class DsEmoVideoSynthesis {
// 图片URL
String imageUrl = "https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/BlogImages/202505131058596.png";
// 音频URL
String audioUrl = "https://dsideal.obs.myhuaweicloud.com/HuangHai/%E5%A4%87%E4%BB%BD/%E5%A4%A7%E5%AE%B6%E5%A5%BD%EF%BC%8C%E8%BF%99%E9%87%8C%E6%98%AF%E6%B5%B7%E5%93%A5AI%E8%AF%BE%E7%A8%8B%EF%BC%8C%E6%88%91%E6%98%AF%E5%B8%AE%E4%BD%A0%E5%AE%9E%E7%8E%B0%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD%E5%8F%98%E7%8E%B0%E7%9A%84%E6%B5%B7%E5%93%A5%E3%80%82.wav";
String audioUrl = "https://dsideal.obs.myhuaweicloud.com/HuangHai/%E5%A4%87%E4%BB%BD/example.wav";
// 人脸边界框 [x, y, width, height]
int[] faceBbox = {10, 20, 30, 40};
// 扩展边界框 [x, y, width, height]
@ -216,7 +216,7 @@ public class DsEmoVideoSynthesis {
// 调用EMO视频合成API
String taskId = synthesisVideo(imageUrl, audioUrl, faceBbox, extBbox, styleLevel);
// 轮询查询任务状态
int maxRetries = 100;
int retryCount = 0;
@ -225,7 +225,7 @@ public class DsEmoVideoSynthesis {
while (retryCount < maxRetries) {
JSONObject result = queryTaskStatus(taskId);
String status = result.getJSONObject("output").getString("status");
String status = result.getJSONObject("output").getString("task_status");
log.info("任务状态: {}", status);
if ("SUCCEEDED".equals(status)) {
@ -249,7 +249,7 @@ public class DsEmoVideoSynthesis {
if (retryCount >= maxRetries) {
log.error("查询任务状态超时,已达到最大重试次数: {}", maxRetries);
}
// 如果获取到了视频URL则下载保存
if (videoUrl != null && !videoUrl.isEmpty()) {
// 创建保存目录
@ -258,7 +258,7 @@ public class DsEmoVideoSynthesis {
String fileName = "emo_" + System.currentTimeMillis() + "_" + taskId + ".mp4";
// 完整保存路径
String savePath = saveDir + "/" + fileName;
// 下载视频
downloadVideo(videoUrl, savePath);
}

Loading…
Cancel
Save