前端-胡立永 1 day ago
parent
commit
2db73f0767
2 changed files with 23 additions and 33 deletions
  1. +12
    -10
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiTTServiceImpl.java
  2. +11
    -23
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletArticle/controller/AppletArticleController.java

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

@ -418,6 +418,17 @@ public class AppletApiTTServiceImpl implements AppletApiTTService {
return CompletableFuture.completedFuture(successCache.getTaskId());
}
// 写入缓存标记生成中text字段保存哈希
AppletTtsCache cache = new AppletTtsCache();
cache.setText(textHash);
cache.setVoiceType(voiceType);
cache.setVolume(volume != null ? volume.doubleValue() : null);
cache.setSpeed(speed != null ? speed.doubleValue() : null);
cache.setSuccess("N");
cache.setState(0);
cache.setCreateTime(new java.util.Date());
appletTtsCacheService.save(cache);
// 应用并发控制等待获取请求许可
log.info("开始等待长文本TTS请求许可,textHash: {}", textHash);
waitForLongTextTtsPermit();
@ -445,17 +456,8 @@ public class AppletApiTTServiceImpl implements AppletApiTTService {
throw new JeecgBootException("创建长文本TTS任务失败,未返回任务ID");
}
// 写入缓存标记生成中text字段保存哈希
AppletTtsCache cache = new AppletTtsCache();
cache.setTaskId(taskId);
cache.setText(textHash);
cache.setVoiceType(voiceType);
cache.setVolume(volume != null ? volume.doubleValue() : null);
cache.setSpeed(speed != null ? speed.doubleValue() : null);
cache.setSuccess("N");
cache.setState(0);
cache.setCreateTime(new java.util.Date());
appletTtsCacheService.save(cache);
appletTtsCacheService.updateById(cache);
log.info("长文本TTS任务创建成功,taskId: {},textHash: {}", taskId, textHash);
return CompletableFuture.completedFuture(taskId);


+ 11
- 23
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletArticle/controller/AppletArticleController.java View File

@ -14,6 +14,7 @@ import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.applet.util.HtmlUtils;
import org.jeecg.modules.demo.appletArticle.entity.AppletArticle;
import org.jeecg.modules.demo.appletArticle.service.IAppletArticleService;
@ -96,20 +97,12 @@ public class AppletArticleController extends JeecgController<AppletArticle, IApp
@RequiresPermissions("appletArticle:applet_article:add")
@PostMapping(value = "/add")
public Result<String> add(@RequestBody AppletArticle appletArticle) {
String content = appletArticle.getContent();
if (content != null && !content.trim().isEmpty()) {
String contentHashcode = HtmlUtils.calculateStringHash(HtmlUtils.stripHtml(content));
appletArticle.setContentHashcode(contentHashcode);
}
appletArticleService.save(appletArticle);
// 触发长文本TTS生成遍历所有启用音色对content进行转换
// try {
// String content = appletArticle.getContent();
// if (content != null && !content.trim().isEmpty()) {
// String code = appletApiTTService.generateLongTextForArticleContentAllTimbres(content);
// appletArticle.setContentHashcode(code);
// appletArticleService.updateById(appletArticle);
// }
// } catch (Exception e) {
// log.warn("文章添加后触发长文本TTS失败: {}", e.getMessage());
// }
return Result.OK("添加成功!");
}
@ -124,16 +117,11 @@ public class AppletArticleController extends JeecgController<AppletArticle, IApp
@RequiresPermissions("appletArticle:applet_article:edit")
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
public Result<String> edit(@RequestBody AppletArticle appletArticle) {
// 触发长文本TTS生成遍历所有启用音色对content进行转换
// try {
// String content = appletArticle.getContent();
// if (content != null && !content.trim().isEmpty()) {
// String code = appletApiTTService.generateLongTextForArticleContentAllTimbres(content);
// appletArticle.setContentHashcode(code);
// }
// } catch (Exception e) {
// log.warn("文章编辑后触发长文本TTS失败: {}", e.getMessage());
// }
String content = appletArticle.getContent();
if (content != null && !content.trim().isEmpty()) {
String contentHashcode = HtmlUtils.calculateStringHash(HtmlUtils.stripHtml(content));
appletArticle.setContentHashcode(contentHashcode);
}
appletArticleService.updateById(appletArticle);
return Result.OK("编辑成功!");
}


Loading…
Cancel
Save