|
|
|
@ -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<AppletTtsCache> 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(); |
|
|
|
|