2025-09-18 11:40:12 +08:00
|
|
|
|
package com.fuyuanshen.app.controller;
|
|
|
|
|
|
|
2025-11-07 16:59:07 +08:00
|
|
|
|
import cn.dev33.satoken.annotation.SaIgnore;
|
2026-02-02 16:06:11 +08:00
|
|
|
|
import com.fuyuanshen.app.domain.bo.AppBusinessFileBo;
|
|
|
|
|
|
import com.fuyuanshen.app.domain.dto.AppAudioFileDto;
|
|
|
|
|
|
import com.fuyuanshen.app.domain.dto.AppFileDto;
|
|
|
|
|
|
import com.fuyuanshen.app.domain.dto.TextToSpeechRequest;
|
|
|
|
|
|
import com.fuyuanshen.app.domain.vo.AppFileVo;
|
2025-10-24 11:22:35 +08:00
|
|
|
|
import com.fuyuanshen.app.service.AudioProcessService;
|
|
|
|
|
|
import com.fuyuanshen.app.service.VideoProcessService;
|
2025-09-18 11:40:12 +08:00
|
|
|
|
import com.fuyuanshen.common.core.domain.R;
|
2025-10-27 09:00:36 +08:00
|
|
|
|
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
|
2025-09-18 11:40:12 +08:00
|
|
|
|
import com.fuyuanshen.common.web.core.BaseController;
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
import org.springframework.http.MediaType;
|
2026-02-02 16:06:11 +08:00
|
|
|
|
import org.springframework.http.ResponseEntity;
|
2025-09-18 11:40:12 +08:00
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
2025-10-24 11:22:35 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
2025-09-18 11:40:12 +08:00
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
2025-10-24 11:22:35 +08:00
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
import java.util.Base64;
|
2025-09-18 11:40:12 +08:00
|
|
|
|
import java.util.List;
|
2025-10-27 09:00:36 +08:00
|
|
|
|
import java.util.concurrent.TimeUnit;
|
2025-09-18 11:40:12 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-24 11:22:35 +08:00
|
|
|
|
* APP 视频处理控制器
|
2025-09-18 11:40:12 +08:00
|
|
|
|
*/
|
|
|
|
|
|
@Validated
|
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping("/app/video")
|
|
|
|
|
|
public class AppVideoController extends BaseController {
|
|
|
|
|
|
|
2025-10-24 11:22:35 +08:00
|
|
|
|
private final VideoProcessService videoProcessService;
|
|
|
|
|
|
private final AudioProcessService audioProcessService;
|
2025-09-18 11:40:12 +08:00
|
|
|
|
|
2025-11-20 16:24:45 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 上传视频转码code默认1:RGB565 2:BGR565
|
|
|
|
|
|
*/
|
2025-10-24 11:22:35 +08:00
|
|
|
|
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
2025-10-27 09:00:36 +08:00
|
|
|
|
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
2025-11-20 16:24:45 +08:00
|
|
|
|
public R<List<String>> uploadVideo(@RequestParam("file") MultipartFile file, @RequestParam(defaultValue = "1") int code) {
|
|
|
|
|
|
return R.ok(videoProcessService.processVideo(file, code));
|
2025-09-18 11:40:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-24 11:22:35 +08:00
|
|
|
|
* 上传音频文件并转码
|
2025-09-18 11:40:12 +08:00
|
|
|
|
*/
|
2025-10-24 11:22:35 +08:00
|
|
|
|
@PostMapping(value = "/audio", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
2025-10-27 09:00:36 +08:00
|
|
|
|
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
2025-10-24 11:22:35 +08:00
|
|
|
|
public R<List<String>> uploadAudio(@RequestParam("file") MultipartFile file) {
|
|
|
|
|
|
return R.ok(audioProcessService.processAudio(file));
|
2025-09-18 11:40:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-24 11:22:35 +08:00
|
|
|
|
* 文字转音频TTS服务
|
2025-09-18 11:40:12 +08:00
|
|
|
|
*/
|
2025-10-24 11:22:35 +08:00
|
|
|
|
@GetMapping("/audioTTS")
|
2025-10-27 09:00:36 +08:00
|
|
|
|
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
2025-10-24 11:22:35 +08:00
|
|
|
|
public R<List<String>> uploadAudioTTS(@RequestParam String text) throws IOException {
|
|
|
|
|
|
return R.ok(audioProcessService.generateStandardPcmData(text));
|
2025-09-18 11:40:12 +08:00
|
|
|
|
}
|
2025-11-07 16:59:07 +08:00
|
|
|
|
|
2026-02-02 16:06:11 +08:00
|
|
|
|
|
2025-11-07 16:59:07 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 提取文本内容(只支持txt/docx)
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping(value = "/extract", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
|
|
|
@RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS,message = "请勿重复提交!")
|
|
|
|
|
|
public R<String> extract(@RequestParam("file") MultipartFile file) throws Exception {
|
|
|
|
|
|
return R.ok("Success",audioProcessService.extract(file));
|
|
|
|
|
|
}
|
2025-12-19 14:06:01 +08:00
|
|
|
|
|
2026-02-02 16:06:11 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 上传音频文件进行处理
|
|
|
|
|
|
* 支持MP3、WAV、PCM格式
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/uploadAudioToOss")
|
|
|
|
|
|
public R<String> uploadAudioToOss(@RequestParam("file") @ModelAttribute AppAudioFileDto bo) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
String result = audioProcessService.uploadAudioToOss(bo);
|
|
|
|
|
|
return R.ok(result);
|
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
|
return R.fail("文件格式错误: " + e.getMessage());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
|
|
return R.fail("上传处理失败: " + e.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 文本转语音
|
|
|
|
|
|
* 支持MP3、WAV、PCM格式
|
|
|
|
|
|
*/
|
|
|
|
|
|
@PostMapping("/ttsToOss")
|
|
|
|
|
|
public R<String> textToSpeech(@RequestBody TextToSpeechRequest request) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (request.getDeviceId() == null) {
|
|
|
|
|
|
return R.fail("设备ID不能为空");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String result = audioProcessService.textToSpeech(
|
|
|
|
|
|
request.getDeviceId(),
|
|
|
|
|
|
request.getText(),
|
|
|
|
|
|
request.getFileSuffix()
|
|
|
|
|
|
);
|
|
|
|
|
|
return R.ok(result);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
return R.fail("文本转语音失败: " + e.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询语音文件列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
@GetMapping("/queryAudioFileList")
|
|
|
|
|
|
public R<List<AppFileVo>> queryAudioFileList(Long deviceId) {
|
|
|
|
|
|
return R.ok(audioProcessService.queryAudioFileList(deviceId));
|
|
|
|
|
|
}
|
2025-09-18 11:40:12 +08:00
|
|
|
|
}
|