otherContent如果content内容是图片,存宽高

This commit is contained in:
wuchunlei
2024-12-11 17:17:56 +08:00
parent 078f05d037
commit 0ac6ab33d5
7 changed files with 134 additions and 108 deletions

View File

@@ -56,22 +56,17 @@ public class BookChapterContentController {
private ShopProductBookService shopProductBookService;
//章节内容单句转成音频
//某一内容转成音频
@RequestMapping("/contentToVoices")
public R contentToVoices(@RequestBody Map<String,Object> params){
//调用百度语音合成 API
// String voices = BaiduVoicesUtils.shortText(params.get("content").toString());
String voices = JacobUtil.toVoice(params.get("content").toString());
if (StringUtils.isEmpty(voices)) {
return R.error("语音上传失败");
}
return R.ok().put("voices", voices);
bookChapterContentService.contentToVoices(params.get("bookChapterContentId").toString());
return R.ok();
}
//按一句话转成音频
//书籍下所有内容转成音频
@RequestMapping("/bookToShortVoices")
public R bookToShortVoices(@RequestBody Map<String,Object> params){
ExecutorService service = Executors.newFixedThreadPool(5);
ExecutorService service = Executors.newFixedThreadPool(10);
List<BookChapterContentEntity> list = bookChapterContentService.list(new LambdaQueryWrapper<BookChapterContentEntity>()
.eq(BookChapterContentEntity::getBookId,params.get("bookId")));
for (BookChapterContentEntity bcc:list){
@@ -79,20 +74,7 @@ public class BookChapterContentController {
service.execute(new Runnable() {
@Override
public void run() {
try {
//调用百度语音合成 API
// String voices = BaiduVoicesUtils.shortText(bcc.getContent());
String voices = JacobUtil.toVoice(bcc.getContent());
if (voices.contains(",")){
bcc.setVoices(voices.split(",")[0]);
bcc.setVoicesSize(voices.split(",")[1]);
}else {
bcc.setVoices(voices);
}
bookChapterContentService.updateById(bcc);
}catch (Exception e) {
e.printStackTrace();
}
bookChapterContentService.contentToVoices(bcc.getId()+"");
}
});
}
@@ -100,7 +82,7 @@ public class BookChapterContentController {
return R.ok();
}
//章节下所有音频合并成一个音频
//某一章节下所有音频合并成一个音频
@RequestMapping("/mergeVoices")
public R mergeVoices(@RequestBody Map<String,Object> params){
List<BookChapterContentEntity> bccs = bookChapterContentService.list(new LambdaQueryWrapper<BookChapterContentEntity>()
@@ -123,7 +105,7 @@ public class BookChapterContentController {
}
}
//所有章节合并音频
//所有章节合并各自音频
@RequestMapping("/mergeVoicesByBookId")
@Transactional
public R mergeVoicesByBookId(@RequestBody Map<String,Object> params){
@@ -131,25 +113,27 @@ public class BookChapterContentController {
List<BookChapterEntity> bcs = bookChapterService.list(new LambdaQueryWrapper<BookChapterEntity>()
.eq(BookChapterEntity::getBookId,params.get("bookId"))
.orderByAsc(BookChapterEntity::getNumber));
ExecutorService service = Executors.newFixedThreadPool(10);
for (BookChapterEntity bc:bcs) {
List<BookChapterContentEntity> bccs = bookChapterContentService.list(new LambdaQueryWrapper<BookChapterContentEntity>()
.eq(BookChapterContentEntity::getBookChatperId,bc.getId())
.orderByAsc(BookChapterContentEntity::getNumber));
List<String> list = new ArrayList<>();
for (BookChapterContentEntity bcc : bccs) {
if (!StringUtils.isEmpty(bcc.getVoices())){
list.add(bcc.getVoices());
service.execute(new Runnable() {
@Override
public void run() {
List<BookChapterContentEntity> bccs = bookChapterContentService.list(new LambdaQueryWrapper<BookChapterContentEntity>()
.eq(BookChapterContentEntity::getBookChatperId,bc.getId())
.orderByAsc(BookChapterContentEntity::getNumber));
List<String> list = new ArrayList<>();
for (BookChapterContentEntity bcc : bccs) {
if (!StringUtils.isEmpty(bcc.getVoices())){
list.add(bcc.getVoices());
}
}
String url = BaiduVoicesUtils.mergeVoices(list);
bc.setVoices(url);
bookChapterService.updateById(bc);
}
}
String url = BaiduVoicesUtils.mergeVoices(list);
if (!StringUtils.isEmpty(url)){
bc.setVoices(url);
bookChapterService.updateById(bc);
}else {
sb.append(bc.getChapter()+"-"+bc.getContent()+"错误");
}
});
}
return R.ok().put("info",sb.toString());
return R.ok();
}
//按章节转成长音频