调整 音频合成, 头衔监测

This commit is contained in:
spllzh
2025-10-06 23:16:59 +08:00
parent 20378e8115
commit 76dedb657a
36 changed files with 1732 additions and 12 deletions

View File

@@ -0,0 +1,180 @@
package com.rj.controller;
import com.rj.dto.VideoSynthesisRequestDto;
import com.rj.entity.VideoSynthesisLog;
import com.rj.service.IVideoSynthesisService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.HashMap;
import java.util.Map;
/**
* 视频合成控制器
*
* @author rj
* @date 2025-01-02
*/
@Slf4j
@RestController
@RequestMapping("/api/video-synthesis")
@Tag(name = "视频合成,根据头像和音频生成视频", description = "视频合成相关接口,根据头像和音频生成视频")
public class VideoSynthesisFromController {
@Autowired
private IVideoSynthesisService videoSynthesisService;
/**
* 视频合成接口
*/
@PostMapping("/synthesize")
@Operation(summary = "视频合成", description = "根据图片和音频生成视频")
public ResponseEntity<Map<String, Object>> synthesizeVideo(@Valid @RequestBody VideoSynthesisRequestDto requestDto) {
Map<String, Object> result = new HashMap<>();
try {
log.info("开始视频合成图片URL: {}, 音频URL: {}", requestDto.getImageUrl(), requestDto.getAudioUrl());
// 执行视频合成
VideoSynthesisLog synthesisLog = videoSynthesisService.synthesizeVideoAndSave(requestDto);
// 构建响应结果
result.put("success", synthesisLog.getSuccess());
result.put("message", synthesisLog.getSuccess() ? "视频合成成功" : "视频合成失败");
result.put("requestId", synthesisLog.getRequestId());
result.put("taskId", synthesisLog.getTaskId());
result.put("taskStatus", synthesisLog.getTaskStatus());
result.put("videoUrl", synthesisLog.getVideoUrl());
result.put("videoDuration", synthesisLog.getVideoDuration());
result.put("videoRatio", synthesisLog.getVideoRatio());
result.put("processingTimeMs", synthesisLog.getProcessingTimeMs());
result.put("imageId", synthesisLog.getImageId());
result.put("audioId", synthesisLog.getAudioId());
result.put("ownerName", synthesisLog.getOwnerName());
result.put("ownerPhone", synthesisLog.getOwnerPhone());
result.put("modelProvider", synthesisLog.getModelProvider());
if (!synthesisLog.getSuccess()) {
result.put("errorMessage", synthesisLog.getErrorMessage());
return ResponseEntity.badRequest().body(result);
}
return ResponseEntity.ok(result);
} catch (Exception e) {
log.error("视频合成失败: {}", e.getMessage(), e);
result.put("success", false);
result.put("message", "视频合成失败: " + e.getMessage());
return ResponseEntity.internalServerError().body(result);
}
}
/**
* 根据请求ID查询视频合成结果
*/
@GetMapping("/result/{requestId}")
@Operation(summary = "查询合成结果", description = "根据请求ID查询视频合成结果")
public ResponseEntity<Map<String, Object>> getSynthesisResult(
@Parameter(description = "请求ID", required = true)
@PathVariable String requestId) {
Map<String, Object> result = new HashMap<>();
try {
VideoSynthesisLog synthesisLog = videoSynthesisService.getVideoSynthesisLogByRequestId(requestId);
if (synthesisLog == null) {
result.put("success", false);
result.put("message", "未找到对应的视频合成记录");
return ResponseEntity.notFound().build();
}
result.put("success", true);
result.put("message", "查询成功");
result.put("requestId", synthesisLog.getRequestId());
result.put("taskId", synthesisLog.getTaskId());
result.put("taskStatus", synthesisLog.getTaskStatus());
result.put("videoUrl", synthesisLog.getVideoUrl());
result.put("videoDuration", synthesisLog.getVideoDuration());
result.put("videoRatio", synthesisLog.getVideoRatio());
result.put("processingTimeMs", synthesisLog.getProcessingTimeMs());
result.put("requestTime", synthesisLog.getRequestTime());
result.put("responseTime", synthesisLog.getResponseTime());
result.put("imageId", synthesisLog.getImageId());
result.put("audioId", synthesisLog.getAudioId());
result.put("ownerName", synthesisLog.getOwnerName());
result.put("ownerPhone", synthesisLog.getOwnerPhone());
result.put("modelProvider", synthesisLog.getModelProvider());
if (!synthesisLog.getSuccess()) {
result.put("errorMessage", synthesisLog.getErrorMessage());
}
return ResponseEntity.ok(result);
} catch (Exception e) {
log.error("查询视频合成结果失败: {}", e.getMessage(), e);
result.put("success", false);
result.put("message", "查询失败: " + e.getMessage());
return ResponseEntity.internalServerError().body(result);
}
}
/**
* 根据任务ID查询视频合成结果
*/
@GetMapping("/result/task/{taskId}")
@Operation(summary = "根据任务ID查询结果", description = "根据任务ID查询视频合成结果")
public ResponseEntity<Map<String, Object>> getSynthesisResultByTaskId(
@Parameter(description = "任务ID", required = true)
@PathVariable String taskId) {
Map<String, Object> result = new HashMap<>();
try {
VideoSynthesisLog synthesisLog = videoSynthesisService.getVideoSynthesisLogByTaskId(taskId);
if (synthesisLog == null) {
result.put("success", false);
result.put("message", "未找到对应的视频合成记录");
return ResponseEntity.notFound().build();
}
result.put("success", true);
result.put("message", "查询成功");
result.put("requestId", synthesisLog.getRequestId());
result.put("taskId", synthesisLog.getTaskId());
result.put("taskStatus", synthesisLog.getTaskStatus());
result.put("videoUrl", synthesisLog.getVideoUrl());
result.put("videoDuration", synthesisLog.getVideoDuration());
result.put("videoRatio", synthesisLog.getVideoRatio());
result.put("processingTimeMs", synthesisLog.getProcessingTimeMs());
result.put("requestTime", synthesisLog.getRequestTime());
result.put("responseTime", synthesisLog.getResponseTime());
result.put("imageId", synthesisLog.getImageId());
result.put("audioId", synthesisLog.getAudioId());
result.put("ownerName", synthesisLog.getOwnerName());
result.put("ownerPhone", synthesisLog.getOwnerPhone());
result.put("modelProvider", synthesisLog.getModelProvider());
if (!synthesisLog.getSuccess()) {
result.put("errorMessage", synthesisLog.getErrorMessage());
}
return ResponseEntity.ok(result);
} catch (Exception e) {
log.error("根据任务ID查询视频合成结果失败: {}", e.getMessage(), e);
result.put("success", false);
result.put("message", "查询失败: " + e.getMessage());
return ResponseEntity.internalServerError().body(result);
}
}
}