文字转音频
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 列表
|
||||
|
||||
Reference in New Issue
Block a user