From 27057bec9dc172451c2069572a937a455087ff0f Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Fri, 31 Oct 2025 12:58:19 +0800 Subject: [PATCH] 1 --- .../service/impl/AppletApiTTServiceImpl.java | 38 +++++++++++++--------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java index af605ce..343b4f9 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java @@ -15,6 +15,7 @@ import com.tencentcloudapi.tts.v20190823.models.CreateTtsTaskResponse; import com.tencentcloudapi.tts.v20190823.models.DescribeTtsTaskStatusRequest; import com.tencentcloudapi.tts.v20190823.models.DescribeTtsTaskStatusResponse; import lombok.extern.log4j.Log4j2; +import org.apache.commons.lang.StringUtils; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.system.util.AppletUserUtil; import org.jeecg.common.util.oss.OssBootUtil; @@ -193,7 +194,8 @@ public class AppletApiTTServiceImpl implements AppletApiTTService { .eq(speed != null, AppletTtsCache::getSpeed, speed != null ? speed.doubleValue() : null) .eq(AppletTtsCache::getSuccess, "Y"); - AppletTtsCache existingCache = appletTtsCacheService.getOne(queryWrapper); + List list = appletTtsCacheService.list(queryWrapper); + AppletTtsCache existingCache = list.size() > 0 ? list.get(0) : null; if (existingCache != null) { // 缓存命中,直接返回缓存的音频ID @@ -201,9 +203,13 @@ public class AppletApiTTServiceImpl implements AppletApiTTService { // 记录播放日志 long endTime = System.currentTimeMillis(); - double elapsedTime = (endTime - startTime) / 1000.0; - savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null, - speed != null ? speed.doubleValue() : null, elapsedTime, true, existingCache.getId()); +// double elapsedTime = (endTime - startTime) / 1000.0; +// savePlayLog(userId, text, voiceType, volume != null ? volume.doubleValue() : null, +// speed != null ? speed.doubleValue() : null, elapsedTime, true, existingCache.getId()); + + if (StringUtils.isBlank(existingCache.getAudioId())){ + throw new JeecgBootException("音频URL无效"); + } return TtsVo.builder() .url(existingCache.getAudioId()) @@ -261,18 +267,18 @@ public class AppletApiTTServiceImpl implements AppletApiTTService { cache.setCreateTime(new java.util.Date()); // 计算音频时长(通过音频文件解析获得真实时长) - Double realDuration = AudioDurationUtil.calculateDuration(audioData); - if (realDuration != null) { - cache.setDuration(realDuration); - log.info("音频真实时长计算成功: {}秒", realDuration); - } else { - // 如果真实时长计算失败,使用文本长度估算作为备选方案 - if (text != null) { - double estimatedDuration = text.length() / 5.0; - cache.setDuration(estimatedDuration); - log.warn("音频真实时长计算失败,使用文本长度估算: {}秒", estimatedDuration); - } - } +// Double realDuration = AudioDurationUtil.calculateDuration(audioData); +// if (realDuration != null) { +// cache.setDuration(realDuration); +// log.info("音频真实时长计算成功: {}秒", realDuration); +// } else { +// // 如果真实时长计算失败,使用文本长度估算作为备选方案 +// if (text != null) { +// double estimatedDuration = text.length() / 5.0; +// cache.setDuration(estimatedDuration); +// log.warn("音频真实时长计算失败,使用文本长度估算: {}秒", estimatedDuration); +// } +// } appletTtsCacheService.save(cache); cacheId = cache.getId();