|
|
|
@ -213,7 +213,7 @@ public class AppletApiTTServiceImpl implements AppletApiTTService { |
|
|
|
|
|
|
|
return TtsVo.builder() |
|
|
|
.url(existingCache.getAudioId()) |
|
|
|
.time(existingCache.getDuration()) |
|
|
|
.time(existingCache.getDuration() == null ? 0 : existingCache.getDuration()) |
|
|
|
.build(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -267,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(); |
|
|
|
@ -292,7 +292,8 @@ public class AppletApiTTServiceImpl implements AppletApiTTService { |
|
|
|
log.info("TTS调用成功,文本长度: {}, 耗时: {}秒", text != null ? text.length() : 0, elapsedTime); |
|
|
|
return TtsVo.builder() |
|
|
|
.url(cache.getAudioId()) |
|
|
|
.time(cache.getDuration()) |
|
|
|
// .time(cache.getDuration()) |
|
|
|
.time(cache.getDuration() == null ? 0 : cache.getDuration()) |
|
|
|
.build(); |
|
|
|
} else { |
|
|
|
// 记录失败的TTS调用日志 |
|
|
|
|