修复bug2
This commit is contained in:
@ -81,6 +81,7 @@ public class AppVideoController extends BaseController {
|
||||
@PostMapping("/uploadAudioToOss")
|
||||
public R<String> uploadAudioToOss(@ModelAttribute AppAudioFileDto bo) {
|
||||
try {
|
||||
bo.setSource("app");
|
||||
String result = audioProcessService.uploadAudioToOss(bo);
|
||||
return R.ok(result);
|
||||
} catch (IllegalArgumentException e) {
|
||||
@ -108,7 +109,8 @@ public class AppVideoController extends BaseController {
|
||||
String result = audioProcessService.textToSpeech(
|
||||
request.getDeviceId(),
|
||||
request.getText(),
|
||||
request.getFileSuffix()
|
||||
request.getFileSuffix(),
|
||||
"app"
|
||||
);
|
||||
return R.ok(result);
|
||||
} catch (Exception e) {
|
||||
@ -122,7 +124,7 @@ public class AppVideoController extends BaseController {
|
||||
*/
|
||||
@GetMapping("/queryAudioFileList")
|
||||
public R<List<AppFileVo>> queryAudioFileList(Long deviceId) {
|
||||
return R.ok(audioProcessService.queryAudioFileList(deviceId));
|
||||
return R.ok(audioProcessService.queryAudioFileList(deviceId,"app"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -14,4 +14,8 @@ public class AppAudioFileDto {
|
||||
private MultipartFile file;
|
||||
|
||||
|
||||
/**
|
||||
* 数据来源 1:app 2:web 3:其他
|
||||
*/
|
||||
private String source;
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package com.fuyuanshen.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.fuyuanshen.app.domain.bo.AppDeviceBindRecordBo;
|
||||
import com.fuyuanshen.app.domain.dto.AppAudioFileDto;
|
||||
import com.fuyuanshen.app.domain.dto.AppFileRenameDto;
|
||||
import com.fuyuanshen.app.domain.vo.AppDeviceBindRecordVo;
|
||||
import com.fuyuanshen.app.http.HttpTtsClient;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.satoken.utils.AppLoginHelper;
|
||||
@ -65,6 +67,7 @@ public class AudioProcessService {
|
||||
private final ISysOssService ossService;
|
||||
private final IAppBusinessFileService appBusinessFileService;
|
||||
private final AppBusinessFileMapper appBusinessFileMapper;
|
||||
private final IAppDeviceBindRecordService appDeviceBindRecordService;
|
||||
|
||||
// String accessKeyId = "LTAI5t66moCkhNC32TDJ5ReP";
|
||||
// String accessKeySecret = "2F3sdoBJ08bYvJcuDgSkLnJwGXsvYH";
|
||||
@ -385,7 +388,8 @@ public class AudioProcessService {
|
||||
appBusinessFileBo.setFileId(upload.getOssId());
|
||||
appBusinessFileBo.setBusinessId(bo.getDeviceId());
|
||||
appBusinessFileBo.setFileType(3L);
|
||||
appBusinessFileBo.setCreateBy(AppLoginHelper.getUserId());
|
||||
Long userId = getUserId(bo.getSource(), bo.getDeviceId());
|
||||
appBusinessFileBo.setCreateBy(userId);
|
||||
savedPath = saveByteArrayToFile(file.getInputStream(), generateRandomFileName(fileSuffix));
|
||||
if (savedPath != null) {
|
||||
log.info("MP3文件已保存: {}", savedPath);
|
||||
@ -409,6 +413,21 @@ public class AudioProcessService {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Long getUserId(String source,Long deviceId){
|
||||
Long userId = null;
|
||||
if("app".equals( source)){
|
||||
userId = AppLoginHelper.getUserId();
|
||||
} else if ("web".equals( source)){
|
||||
AppDeviceBindRecordBo appDeviceBindRecordBo = new AppDeviceBindRecordBo();
|
||||
appDeviceBindRecordBo.setDeviceId(deviceId);
|
||||
appDeviceBindRecordBo.setCommunicationMode(0);
|
||||
List<AppDeviceBindRecordVo> appDeviceBindRecordVos = appDeviceBindRecordService.queryList(appDeviceBindRecordBo);
|
||||
if (appDeviceBindRecordVos != null && !appDeviceBindRecordVos.isEmpty()){
|
||||
userId = appDeviceBindRecordVos.get(0).getBindingUserId();
|
||||
}
|
||||
}
|
||||
return userId;
|
||||
}
|
||||
/**
|
||||
* 校验音频文件格式
|
||||
*/
|
||||
@ -448,7 +467,7 @@ public class AudioProcessService {
|
||||
return SUPPORTED_FORMATS.contains(ext);
|
||||
}
|
||||
|
||||
public String textToSpeech(Long deviceId,String text, String fileSuffix) {
|
||||
public String textToSpeech(Long deviceId,String text, String fileSuffix,String source) {
|
||||
//支持PCM/WAV/MP3格式
|
||||
if (fileSuffix == null || fileSuffix.isEmpty()) {
|
||||
fileSuffix = "mp3";
|
||||
@ -485,7 +504,7 @@ public class AudioProcessService {
|
||||
String fileName = generateRandomFileName(fileSuffix);
|
||||
savedMp3VolumePath = directory + "/" + fileName;
|
||||
log.info("保存MP3文件: {}", savedMp3VolumePath);
|
||||
FfmpegVolumeUtil.increaseMp3Volume(savedPath, savedMp3VolumePath, 12);
|
||||
FfmpegVolumeUtil.increaseMp3Volume(savedPath, savedMp3VolumePath, 8);
|
||||
|
||||
File file = new File(savedMp3VolumePath);
|
||||
String fileHash = fileHashUtil.getFileHash(file,"SHA-256");
|
||||
@ -499,7 +518,8 @@ public class AudioProcessService {
|
||||
appBusinessFileBo.setFileId(upload.getOssId());
|
||||
appBusinessFileBo.setBusinessId(deviceId);
|
||||
appBusinessFileBo.setFileType(3L);
|
||||
appBusinessFileBo.setCreateBy(AppLoginHelper.getUserId());
|
||||
Long userId = getUserId(source, deviceId);
|
||||
appBusinessFileBo.setCreateBy(userId);
|
||||
appBusinessFileService.insertByBo(appBusinessFileBo);
|
||||
if (upload != null) {
|
||||
return upload.getUrl();
|
||||
@ -547,14 +567,14 @@ public class AudioProcessService {
|
||||
return timestamp+extension;
|
||||
}
|
||||
|
||||
public List<AppFileVo> queryAudioFileList(Long deviceId) {
|
||||
public List<AppFileVo> queryAudioFileList(Long deviceId,String source) {
|
||||
if(deviceId == null){
|
||||
return null;
|
||||
}
|
||||
// Long userId = LoginHelper.getUserId();
|
||||
Long userId = getUserId(source, deviceId);
|
||||
AppBusinessFileBo bo = new AppBusinessFileBo();
|
||||
bo.setBusinessId(deviceId);
|
||||
// bo.setCreateBy(userId);
|
||||
bo.setCreateBy(userId);
|
||||
bo.setFileType(3L);
|
||||
return appBusinessFileService.queryAppFileList(bo);
|
||||
}
|
||||
|
||||
@ -76,6 +76,7 @@ public class WebVideoController extends BaseController {
|
||||
@PostMapping("/uploadAudioToOss")
|
||||
public R<String> uploadAudioToOss(@ModelAttribute AppAudioFileDto bo) {
|
||||
try {
|
||||
bo.setSource("web");
|
||||
String result = audioProcessService.uploadAudioToOss(bo);
|
||||
return R.ok(result);
|
||||
} catch (IllegalArgumentException e) {
|
||||
@ -100,7 +101,8 @@ public class WebVideoController extends BaseController {
|
||||
String result = audioProcessService.textToSpeech(
|
||||
request.getDeviceId(),
|
||||
request.getText(),
|
||||
request.getFileSuffix()
|
||||
request.getFileSuffix(),
|
||||
"web"
|
||||
);
|
||||
return R.ok(result);
|
||||
} catch (Exception e) {
|
||||
@ -114,7 +116,7 @@ public class WebVideoController extends BaseController {
|
||||
*/
|
||||
@GetMapping("/queryAudioFileList")
|
||||
public R<List<AppFileVo>> queryAudioFileList(Long deviceId) {
|
||||
return R.ok(audioProcessService.queryAudioFileList(deviceId));
|
||||
return R.ok(audioProcessService.queryAudioFileList(deviceId,"web"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -46,6 +46,9 @@ public class AppDeviceBindRecordBo extends BaseEntity {
|
||||
* 绑定时间
|
||||
*/
|
||||
private Date bindingTime;
|
||||
|
||||
/**
|
||||
* 通讯方式 0:4G;1:蓝牙,2 4G&蓝牙
|
||||
*/
|
||||
private Integer communicationMode;
|
||||
|
||||
}
|
||||
|
||||
@ -76,6 +76,7 @@ public class AppDeviceBindRecordServiceImpl implements IAppDeviceBindRecordServi
|
||||
lqw.eq(bo.getDeviceId() != null, AppDeviceBindRecord::getDeviceId, bo.getDeviceId());
|
||||
lqw.eq(bo.getBindingUserId() != null, AppDeviceBindRecord::getBindingUserId, bo.getBindingUserId());
|
||||
lqw.eq(bo.getBindingTime() != null, AppDeviceBindRecord::getBindingTime, bo.getBindingTime());
|
||||
lqw.eq(bo.getCommunicationMode() != null, AppDeviceBindRecord::getCommunicationMode, bo.getCommunicationMode());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user