|
@@ -9,8 +9,8 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.jd.entity.ExplainDetails;
|
|
|
-import com.jd.mapper.ExplainDetailsMapper;
|
|
|
+import com.jd.entity.ExplainDetails;
|
|
|
+import com.jd.mapper.ExplainDetailsMapper;
|
|
|
|
|
|
|
|
|
import com.jd.service.ExplainDetailsService;
|
|
@@ -24,7 +24,7 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
@Service
|
|
|
-public class ExplainDetailsServiceImpl extends ServiceImpl<ExplainDetailsMapper,ExplainDetails> implements ExplainDetailsService {
|
|
|
+public class ExplainDetailsServiceImpl extends ServiceImpl<ExplainDetailsMapper, ExplainDetails> implements ExplainDetailsService {
|
|
|
|
|
|
private static final String VOCIE_HTTP = "http://23.37.100.80:8093";
|
|
|
|
|
@@ -35,15 +35,19 @@ public class ExplainDetailsServiceImpl extends ServiceImpl<ExplainDetailsMapper,
|
|
|
private String rootPath;
|
|
|
|
|
|
@Override
|
|
|
- public IPage<ExplainDetails> queryPage(Page page,ExplainDetails explainDetails) {
|
|
|
- return baseMapper.queryPage(page,explainDetails);
|
|
|
+ public IPage<ExplainDetails> queryPage(Page page, ExplainDetails explainDetails) {
|
|
|
+ return baseMapper.queryPage(page, explainDetails);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean saveBean(ExplainDetails explainDetails) {
|
|
|
//处理语音转换
|
|
|
explainDetails.setAudioUrl(this.play(explainDetails.getAudioContent()));
|
|
|
-
|
|
|
+ //删除原来的音频文件
|
|
|
+ File file = new File(filePath + explainDetails.getAudioUrl());
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
explainDetails.setCreateTime(DateUtil.now());
|
|
|
return baseMapper.insert(explainDetails) > 0;
|
|
|
}
|
|
@@ -52,7 +56,11 @@ public class ExplainDetailsServiceImpl extends ServiceImpl<ExplainDetailsMapper,
|
|
|
public Boolean updateBean(ExplainDetails explainDetails) {
|
|
|
//处理语音转换
|
|
|
explainDetails.setAudioUrl(this.play(explainDetails.getAudioContent()));
|
|
|
-
|
|
|
+ //删除原来的音频文件
|
|
|
+ File file = new File(filePath + explainDetails.getAudioUrl());
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
explainDetails.setCreateTime(DateUtil.now());
|
|
|
return baseMapper.updateById(explainDetails) > 0;
|
|
|
}
|
|
@@ -66,18 +74,18 @@ public class ExplainDetailsServiceImpl extends ServiceImpl<ExplainDetailsMapper,
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
HashMap<String, Object> paramMap = new HashMap<>();
|
|
|
paramMap.put("txt", txt);
|
|
|
- String result = HttpUtil.post(VOCIE_HTTP+"/awaken/tts", paramMap);
|
|
|
+ String result = HttpUtil.post(VOCIE_HTTP + "/awaken/tts", paramMap);
|
|
|
if (!StrUtil.isBlank(result)) {
|
|
|
JSONObject obj = JSONUtil.parseObj(result);
|
|
|
System.err.println(obj);
|
|
|
// 下载音频文件
|
|
|
- File file = FileUtil.file(filePath + "/" + rootPath + "/audio"+ "/" + obj.getStr("data"));
|
|
|
- try{
|
|
|
- if(!file.exists()){
|
|
|
+ File file = FileUtil.file(filePath + "/" + rootPath + "/audio" + "/" + obj.getStr("data"));
|
|
|
+ try {
|
|
|
+ if (!file.exists()) {
|
|
|
// file.mkdirs();
|
|
|
file.createNewFile();
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.error("文件转换失败");
|
|
|
}
|