|
|
@@ -8,6 +8,8 @@ import com.fs.aicall.service.ICcParamsService;
|
|
|
import com.fs.aicall.service.ICcTtsAliyunService;
|
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.company.domain.CompanyVoiceCloneRef;
|
|
|
+import com.fs.company.mapper.CompanyVoiceCloneRefMapper;
|
|
|
import com.fs.company.service.ICompanyVoiceCloneService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import okhttp3.*;
|
|
|
@@ -72,6 +74,9 @@ public class CompanyVoiceCloneServiceImpl implements ICompanyVoiceCloneService {
|
|
|
@Autowired
|
|
|
private ICcTtsAliyunService ccTtsAliyunService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CompanyVoiceCloneRefMapper companyVoiceCloneRefMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 上传并训练
|
|
|
* @param voiceName 音色名称
|
|
|
@@ -84,7 +89,7 @@ public class CompanyVoiceCloneServiceImpl implements ICompanyVoiceCloneService {
|
|
|
@Override
|
|
|
public AjaxResult uploadAndTrain(String voiceName, String speakerId,
|
|
|
Integer language, Integer modelType,
|
|
|
- MultipartFile file) {
|
|
|
+ MultipartFile file,Long companyId,Long companyUserId) {
|
|
|
if (file == null || file.isEmpty()) {
|
|
|
return AjaxResult.error("请选择音频文件");
|
|
|
}
|
|
|
@@ -127,7 +132,8 @@ public class CompanyVoiceCloneServiceImpl implements ICompanyVoiceCloneService {
|
|
|
|
|
|
if (statusCode == 0) {
|
|
|
// 训练成功,写入音色表
|
|
|
- addSpeakerId(voiceName, speakerId);
|
|
|
+ CcTtsAliyun ttsAliyun = addSpeakerId(voiceName, speakerId);
|
|
|
+ addCompanyVoiceRelation(companyId, ttsAliyun.getId(), companyUserId);
|
|
|
|
|
|
// 查询训练状态
|
|
|
boolean modelReady = getStatus(appid, token, speakerId);
|
|
|
@@ -260,7 +266,7 @@ public class CompanyVoiceCloneServiceImpl implements ICompanyVoiceCloneService {
|
|
|
* @param nameParam
|
|
|
* @param speakerId
|
|
|
*/
|
|
|
- private synchronized void addSpeakerId(String nameParam, String speakerId) {
|
|
|
+ private synchronized CcTtsAliyun addSpeakerId(String nameParam, String speakerId) {
|
|
|
CcTtsAliyun ttsSpeaker = ccTtsAliyunService.selectCcTtsAliyunByVoiceCode(speakerId);
|
|
|
String name = nameParam.replace("'", "").replace(" ", "");
|
|
|
if (name.length() > 20) {
|
|
|
@@ -287,9 +293,14 @@ public class CompanyVoiceCloneServiceImpl implements ICompanyVoiceCloneService {
|
|
|
} else {
|
|
|
ccTtsAliyunService.insertCcTtsAliyun(ttsSpeaker);
|
|
|
}
|
|
|
+
|
|
|
+ // 重新查一次,确保拿到最新id
|
|
|
+ CcTtsAliyun saved = ccTtsAliyunService.selectCcTtsAliyunByVoiceCode(speakerId);
|
|
|
log.info("save doubaovcl speakerId succeed. {} {}", name, speakerId);
|
|
|
+ return saved;
|
|
|
} catch (Exception e) {
|
|
|
log.error("save doubaovcl speakerId error: {}", e.getMessage(), e);
|
|
|
+ throw new RuntimeException("保存音色失败", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -388,4 +399,35 @@ public class CompanyVoiceCloneServiceImpl implements ICompanyVoiceCloneService {
|
|
|
.writeTimeout(60, TimeUnit.SECONDS)
|
|
|
.build();
|
|
|
}
|
|
|
+
|
|
|
+ private synchronized void addCompanyVoiceRelation(Long companyId, Integer ttsId,Long companyUserId) {
|
|
|
+ if (companyId == null) {
|
|
|
+ throw new RuntimeException("companyId为空,无法保存公司音色关联");
|
|
|
+ }
|
|
|
+ if (ttsId == null) {
|
|
|
+ throw new RuntimeException("ttsId为空,无法保存公司音色关联");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ CompanyVoiceCloneRef ref = companyVoiceCloneRefMapper.selectByCompanyIdAndTtsId(companyId ,companyUserId, ttsId);
|
|
|
+ if (ref == null) {
|
|
|
+ ref = new CompanyVoiceCloneRef();
|
|
|
+ ref.setCompanyId(companyId);
|
|
|
+ ref.setCompanyUserId(companyUserId);
|
|
|
+ ref.setTtsId(ttsId);
|
|
|
+ ref.setStatus(1);
|
|
|
+ ref.setCreateBy("system");
|
|
|
+ ref.setUpdateBy("system");
|
|
|
+ companyVoiceCloneRefMapper.insertCompanyVoiceCloneRef(ref);
|
|
|
+ } else {
|
|
|
+ ref.setStatus(1);
|
|
|
+ ref.setUpdateBy("system");
|
|
|
+ companyVoiceCloneRefMapper.updateCompanyVoiceCloneRef(ref);
|
|
|
+ }
|
|
|
+ log.info("保存公司音色关联成功,companyId={}, ttsId={}", companyId, ttsId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("保存公司音色关联失败,companyId={}, ttsId={}", companyId, ttsId, e);
|
|
|
+ throw new RuntimeException("保存公司音色关联失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|