调整 音频合成
This commit is contained in:
@@ -23,6 +23,16 @@ public interface IFaceDetectLogService extends IService<FaceDetectLog> {
|
||||
*/
|
||||
FaceDetectLog detectFaceAndSave(String imageUrl);
|
||||
|
||||
/**
|
||||
* 执行人脸检测并保存日志(带扩展信息)
|
||||
* @param imageUrl 图片URL
|
||||
* @param ownerName 所属人姓名
|
||||
* @param ownerPhone 所属人电话
|
||||
* @param avatarName 头像名称
|
||||
* @return 人脸检测日志对象
|
||||
*/
|
||||
FaceDetectLog detectFaceAndSave(String imageUrl, String ownerName, String ownerPhone, String avatarName);
|
||||
|
||||
/**
|
||||
* 分页查询人脸检测日志
|
||||
* @param current 当前页
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.rj.service;
|
||||
|
||||
import com.rj.entity.TtsRequestLog;
|
||||
import com.rj.utils.MinIOUrlGenerator;
|
||||
|
||||
/**
|
||||
* TTS请求日志服务接口
|
||||
@@ -25,4 +26,19 @@ public interface ITtsRequestLogService {
|
||||
* @return 请求日志
|
||||
*/
|
||||
TtsRequestLog getTtsRequestLogById(String id);
|
||||
|
||||
/**
|
||||
* 根据音频名称设置短链接
|
||||
*
|
||||
* @return 是否设置成功
|
||||
*/
|
||||
boolean setShortUrlByAudioName(MinIOUrlGenerator.UrlInfo urlInfo );
|
||||
|
||||
/**
|
||||
* 根据音频名称设置短链接(使用默认15分钟过期时间)
|
||||
*
|
||||
* @param audioName 音频名称
|
||||
* @return 是否设置成功
|
||||
*/
|
||||
boolean setShortUrlByAudioName(String audioName);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class SiliconFlowTtsService {
|
||||
|
||||
// 确保voice参数正确设置
|
||||
if (request.getVoice() == null || request.getVoice().trim().isEmpty()) {
|
||||
// 根据模型设置默认voice参数
|
||||
// 根据模型设置默认voice参数 FunAudioLLM/CosyVoice2-0.5B:claire
|
||||
String model = request.getModel();
|
||||
if (model != null && model.contains("fnlp/MOSS-TTSD-v0.5")) {
|
||||
request.setVoice("fnlp/MOSS-TTSD-v0.5:claire");
|
||||
@@ -145,7 +145,7 @@ public class SiliconFlowTtsService {
|
||||
}
|
||||
|
||||
// 保存请求日志到数据库
|
||||
saveTtsRequestLog(requestLog, request, ttsResponse, startTime, null);
|
||||
saveTtsRequestLog(requestLog, request, ttsResponse, startTime, null, fileName);
|
||||
|
||||
log.info("TTS请求成功,音频数据长度: {} bytes, 估算时长: {:.2f}秒, MinIO URL: {}, 临时URL: {}",
|
||||
audioBytes.length, estimatedDuration, minioUrl, tempUrlInfo != null ? tempUrlInfo.getUrl() : "无");
|
||||
@@ -158,9 +158,10 @@ public class SiliconFlowTtsService {
|
||||
} catch (Exception e) {
|
||||
log.error("TTS请求异常: {}", e.getMessage(), e);
|
||||
|
||||
|
||||
// 保存错误日志到数据库
|
||||
SiliconFlowTtsResponse errorResponse = SiliconFlowTtsResponse.error("TTS请求异常: " + e.getMessage());
|
||||
saveTtsRequestLog(requestLog, request, errorResponse, startTime, e.getMessage());
|
||||
saveTtsRequestLog(requestLog, request, errorResponse, startTime, e.getMessage(), null);
|
||||
|
||||
return errorResponse;
|
||||
}
|
||||
@@ -296,9 +297,10 @@ public class SiliconFlowTtsService {
|
||||
* @param response TTS响应
|
||||
* @param startTime 开始时间
|
||||
* @param errorMessage 错误信息
|
||||
* @param audioFileName 音频文件名
|
||||
*/
|
||||
private void saveTtsRequestLog(TtsRequestLog requestLog, SiliconFlowTtsRequest request,
|
||||
SiliconFlowTtsResponse response, long startTime, String errorMessage) {
|
||||
SiliconFlowTtsResponse response, long startTime, String errorMessage, String audioFileName) {
|
||||
try {
|
||||
long processingTime = System.currentTimeMillis() - startTime;
|
||||
|
||||
@@ -315,11 +317,13 @@ public class SiliconFlowTtsService {
|
||||
requestLog.setSampleRate(request.getSampleRate());
|
||||
requestLog.setCreatorName(request.getCreatorName());
|
||||
requestLog.setCreatorPhone(request.getCreatorPhone());
|
||||
requestLog.setAudioName(request.getAudioName());
|
||||
|
||||
// 设置响应信息
|
||||
requestLog.setStatus(response.isSuccess() ? "SUCCESS" : "FAILED");
|
||||
requestLog.setDuration(response.getDuration());
|
||||
requestLog.setMinioUrl(response.getMinioUrl()); // 临时访问URL
|
||||
requestLog.setAudioName(audioFileName); // 音频文件名
|
||||
requestLog.setShortUrl(response.getShortUrl()); // 短链URL(与MinIO URL相同)
|
||||
requestLog.setShortUrlExpireTime(response.getShortUrlExpireTime());
|
||||
requestLog.setProcessingTimeMs(processingTime);
|
||||
|
||||
@@ -55,6 +55,11 @@ public interface ICustomerProfileAnalysisService extends IService<CustomerProfil
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -90,6 +90,11 @@ public class CustomerProfileAnalysisServiceImpl extends ServiceImpl<CustomerProf
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,9 +53,16 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
* 执行人脸检测并保存日志
|
||||
*/
|
||||
public FaceDetectLog detectFaceAndSave(String imageUrl) {
|
||||
return detectFaceAndSave(imageUrl, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行人脸检测并保存日志(带扩展信息)
|
||||
*/
|
||||
public FaceDetectLog detectFaceAndSave(String imageUrl, String ownerName, String ownerPhone, String avatarName) {
|
||||
if (apiKey == null || apiKey.trim().isEmpty()) {
|
||||
log.error("DASHSCOPE_API_KEY未配置");
|
||||
return createErrorLog(imageUrl, "DASHSCOPE_API_KEY未配置");
|
||||
return createErrorLog(imageUrl, "DASHSCOPE_API_KEY未配置", ownerName, ownerPhone, avatarName);
|
||||
}
|
||||
|
||||
// 创建日志记录
|
||||
@@ -66,6 +73,9 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
faceDetectLog.setRequestId(requestId);
|
||||
faceDetectLog.setModel("liveportrait-detect");
|
||||
faceDetectLog.setImageUrl(imageUrl);
|
||||
faceDetectLog.setOwnerName(ownerName);
|
||||
faceDetectLog.setOwnerPhone(ownerPhone);
|
||||
faceDetectLog.setAvatarName(avatarName);
|
||||
faceDetectLog.setRequestTime(requestTime);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
@@ -217,10 +227,20 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
* 创建错误日志
|
||||
*/
|
||||
private FaceDetectLog createErrorLog(String imageUrl, String errorMessage) {
|
||||
return createErrorLog(imageUrl, errorMessage, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建错误日志(带扩展信息)
|
||||
*/
|
||||
private FaceDetectLog createErrorLog(String imageUrl, String errorMessage, String ownerName, String ownerPhone, String avatarName) {
|
||||
FaceDetectLog faceDetectLog = new FaceDetectLog();
|
||||
faceDetectLog.setRequestId(UUID.randomUUID().toString());
|
||||
faceDetectLog.setModel("liveportrait-detect");
|
||||
faceDetectLog.setImageUrl(imageUrl);
|
||||
faceDetectLog.setOwnerName(ownerName);
|
||||
faceDetectLog.setOwnerPhone(ownerPhone);
|
||||
faceDetectLog.setAvatarName(avatarName);
|
||||
faceDetectLog.setRequestTime(LocalDateTime.now());
|
||||
faceDetectLog.setResponseTime(LocalDateTime.now());
|
||||
faceDetectLog.setSuccess(false);
|
||||
|
||||
@@ -3,10 +3,14 @@ package com.rj.service.impl;
|
||||
import com.rj.entity.TtsRequestLog;
|
||||
import com.rj.mapper.TtsRequestLogMapper;
|
||||
import com.rj.service.ITtsRequestLogService;
|
||||
import com.rj.utils.MinIOUrlGenerator;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* TTS请求日志服务实现类
|
||||
*
|
||||
@@ -20,6 +24,9 @@ public class TtsRequestLogServiceImpl implements ITtsRequestLogService {
|
||||
@Autowired
|
||||
private TtsRequestLogMapper ttsRequestLogMapper;
|
||||
|
||||
@Autowired
|
||||
private MinIOUrlGenerator urlGenerator;
|
||||
|
||||
@Override
|
||||
public boolean saveTtsRequestLog(TtsRequestLog requestLog) {
|
||||
try {
|
||||
@@ -41,4 +48,48 @@ public class TtsRequestLogServiceImpl implements ITtsRequestLogService {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setShortUrlByAudioName(MinIOUrlGenerator.UrlInfo urlInfo ) {
|
||||
try {
|
||||
if (urlInfo == null || urlInfo.getFileName().trim().isEmpty()) {
|
||||
log.error("音频名称不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 根据音频名称查询日志记录
|
||||
LambdaQueryWrapper<TtsRequestLog> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TtsRequestLog::getAudioName, urlInfo.getFileName());
|
||||
TtsRequestLog requestLog = ttsRequestLogMapper.selectOne(queryWrapper);
|
||||
|
||||
if (requestLog == null) {
|
||||
log.error("未找到音频名称为 {} 的日志记录", urlInfo.getFileName());
|
||||
return false;
|
||||
}
|
||||
|
||||
// 更新日志记录的短链接信息
|
||||
requestLog.setShortUrl(urlInfo.getUrl());
|
||||
requestLog.setShortUrlExpireTime(urlInfo.getExpiresAt());
|
||||
requestLog.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
int result = ttsRequestLogMapper.updateById(requestLog);
|
||||
if (result > 0) {
|
||||
log.info("成功为音频 {} 设置短链接: {}, 过期时间: {}",
|
||||
urlInfo.getFileName(), urlInfo.getUrl(), urlInfo.getFormattedExpiresAt());
|
||||
return true;
|
||||
} else {
|
||||
log.error("更新音频 {} 的短链接失败", urlInfo.getFileName());
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("根据音频名称设置短链接失败: 音频名称={}, 错误={}", urlInfo.getFileName(), e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setShortUrlByAudioName(String audioName) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,11 @@ public interface IMenuService extends IService<Menu> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -57,6 +57,11 @@ public interface IUserRoleService extends IService<UserRole> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -61,6 +61,11 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -61,6 +61,11 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -61,6 +61,11 @@ public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> i
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.rj.service.sys.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.rj.common.PasswordUtil;
|
||||
import com.rj.entity.sys.User;
|
||||
import com.rj.mapper.sys.UserMapper;
|
||||
@@ -13,9 +12,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -54,6 +51,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
||||
loginResponse.setUserId(user.getUserId());
|
||||
loginResponse.setUserName(user.getUserName());
|
||||
loginResponse.setEmail(user.getEmail());
|
||||
loginResponse.setPhone(user.getPhone());
|
||||
loginResponse.setAvatar(user.getAvatar());
|
||||
loginResponse.setToken(token);
|
||||
loginResponse.setLoginTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
|
||||
Reference in New Issue
Block a user