前端-胡立永 1 week ago
parent
commit
27057bec9d
1 changed files with 22 additions and 16 deletions
  1. +22
    -16
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java

+ 22
- 16
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java View File

@ -15,6 +15,7 @@ import com.tencentcloudapi.tts.v20190823.models.CreateTtsTaskResponse;
import com.tencentcloudapi.tts.v20190823.models.DescribeTtsTaskStatusRequest; import com.tencentcloudapi.tts.v20190823.models.DescribeTtsTaskStatusRequest;
import com.tencentcloudapi.tts.v20190823.models.DescribeTtsTaskStatusResponse; import com.tencentcloudapi.tts.v20190823.models.DescribeTtsTaskStatusResponse;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.util.AppletUserUtil; import org.jeecg.common.system.util.AppletUserUtil;
import org.jeecg.common.util.oss.OssBootUtil; 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(speed != null, AppletTtsCache::getSpeed, speed != null ? speed.doubleValue() : null)
.eq(AppletTtsCache::getSuccess, "Y"); .eq(AppletTtsCache::getSuccess, "Y");
AppletTtsCache existingCache = appletTtsCacheService.getOne(queryWrapper);
List<AppletTtsCache> list = appletTtsCacheService.list(queryWrapper);
AppletTtsCache existingCache = list.size() > 0 ? list.get(0) : null;
if (existingCache != null) { if (existingCache != null) {
// 缓存命中直接返回缓存的音频ID // 缓存命中直接返回缓存的音频ID
@ -201,9 +203,13 @@ public class AppletApiTTServiceImpl implements AppletApiTTService {
// 记录播放日志 // 记录播放日志
long endTime = System.currentTimeMillis(); 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() return TtsVo.builder()
.url(existingCache.getAudioId()) .url(existingCache.getAudioId())
@ -261,18 +267,18 @@ public class AppletApiTTServiceImpl implements AppletApiTTService {
cache.setCreateTime(new java.util.Date()); 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); appletTtsCacheService.save(cache);
cacheId = cache.getId(); cacheId = cache.getId();


Loading…
Cancel
Save