文字转音频

This commit is contained in:
wuchunlei
2024-12-06 14:37:06 +08:00
parent 62ab9fbbb2
commit 5e232e932a
2 changed files with 178 additions and 17 deletions

View File

@@ -52,6 +52,62 @@ public class BookChapterContentController {
private UserEbookBuyService userEbookBuyService;
@Autowired
private ShopProductBookService shopProductBookService;
//章节内容单句转成音频
@RequestMapping("/contentToVoices")
public R contentToVoices(@RequestBody Map<String,Object> params){
//调用百度语音合成 API
String voices = BaiduVoicesUtils.shortText(params.get("content").toString());
if (StringUtils.isEmpty(voices)) {
return R.error("语音上传失败");
}
return R.ok().put("voices", voices);
}
//书籍全部章节转成音频
@RequestMapping("/bookToVoices")
public R bookToVoices(@RequestBody Map<String,Object> params){
// 1、创建服务创建线程池
ExecutorService service = Executors.newFixedThreadPool(5);
List<BookChapterContentEntity> list = bookChapterContentService.list(new LambdaQueryWrapper<BookChapterContentEntity>()
.eq(BookChapterContentEntity::getBookId,params.get("bookId")));
for (BookChapterContentEntity bcc:list){
if (!bcc.getContent().contains("https")&&!"".equals(bcc.getContent())){
service.execute(new Runnable() {
@Override
public void run() {
//调用百度语音合成 API
String voices = BaiduVoicesUtils.shortText(bcc.getContent());
bcc.setVoices(voices);
bookChapterContentService.updateById(bcc);
}
});
}
}
return R.ok();
}
/**
* 列表