修复bug2
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user