From 352c44a28081536a2561e4784ebe55f3d98585bc Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Mon, 11 Mar 2024 18:12:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E8=B5=9B=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtss/services/voice/VoiceService.java | 114 +++++++++--------- .../mybatis/mapper/racetr/RacetrTaskDAO.xml | 2 +- 2 files changed, 60 insertions(+), 56 deletions(-) diff --git a/src/main/java/club/joylink/rtss/services/voice/VoiceService.java b/src/main/java/club/joylink/rtss/services/voice/VoiceService.java index 68ee2407f..cf582f94d 100644 --- a/src/main/java/club/joylink/rtss/services/voice/VoiceService.java +++ b/src/main/java/club/joylink/rtss/services/voice/VoiceService.java @@ -19,66 +19,70 @@ import java.util.Objects; @Component public class VoiceService { - private final MinioClientUtil voiceSynthesisUtil; - private final MinioClientUtil voiceRecognitionUtil; - private final static String SYNTHESIS_FOLDER = "synthesis"; - private final static String RECOGNITION_FOLDER = "recognition"; + private final MinioClientUtil voiceSynthesisUtil; + private final MinioClientUtil voiceRecognitionUtil; + private final static String SYNTHESIS_FOLDER = "synthesis"; + private final static String RECOGNITION_FOLDER = "recognition"; - @Autowired - @Qualifier(value = "baiDuVoiceService2") - private IVoiceService2 voiceService; + @Autowired + @Qualifier(value = "baiDuVoiceService2") + private IVoiceService2 voiceService; - public VoiceService(MinioClientConfig minioClientConfig){ - this.voiceSynthesisUtil = MinioClientUtil.getInstance(minioClientConfig,SYNTHESIS_FOLDER); - this.voiceRecognitionUtil = MinioClientUtil.getInstance(minioClientConfig,RECOGNITION_FOLDER); + public VoiceService(MinioClientConfig minioClientConfig) { + this.voiceSynthesisUtil = MinioClientUtil.getInstance(minioClientConfig, SYNTHESIS_FOLDER); + this.voiceRecognitionUtil = MinioClientUtil.getInstance(minioClientConfig, RECOGNITION_FOLDER); + } + + /** + * 语音识别 + * + * @param vo + * @return + */ + public VoiceRecognitionResult voiceRecognition(VoiceRecognitionVO vo) { + String fileName = String.format("%s.wav", System.currentTimeMillis()); + this.uploadFile(voiceRecognitionUtil, vo.getData(), fileName, RECOGNITION_FOLDER); + String filePath = this.voiceRecognitionUtil.getDownLoadPath(fileName); + VoiceAsrResult voiceResult = voiceService.recognition(vo); + return new VoiceRecognitionResult(filePath, voiceResult.getResult().get(0)); + } + + /** + * 语音合成 + * + * @param vo + * @return + */ + public VoiceCompose synthesis(BaseVoiceSynthesisVO vo) { + String md5Code = vo.md5Code(); + String fileName = String.format("%s.wav", md5Code); + if (Objects.equals(false, this.voiceSynthesisUtil.checkFileIsExist(fileName))) { + byte[] bytes = voiceService.voiceSynthesis(vo); + byte[] data = bytes; + this.uploadFile(voiceSynthesisUtil, data, fileName, SYNTHESIS_FOLDER); } + String filePath = this.voiceSynthesisUtil.getDownLoadPath(fileName); + return new VoiceCompose(filePath, md5Code, vo.getMessage()); + } - /** - * 语音识别 - * @param vo - * @return - */ - public VoiceRecognitionResult voiceRecognition(VoiceRecognitionVO vo){ - String fileName = String.format("%s.wav",System.currentTimeMillis()); - this.uploadFile(voiceRecognitionUtil,vo.getData(),fileName,RECOGNITION_FOLDER); - String filePath = this.voiceRecognitionUtil.getDownLoadPath(fileName); - VoiceAsrResult voiceResult = voiceService.recognition(vo); - return new VoiceRecognitionResult(filePath,voiceResult.getResult().get(0)); - } + /** + * 语音合成返回原数据 + * + * @param vo + * @return + */ + public byte[] synthesisSource(BaseVoiceSynthesisVO vo) { + byte[] data = voiceService.voiceSynthesis(vo); + return data; + } - /** - * 语音合成 - * @param vo - * @return - */ - public VoiceCompose synthesis(BaseVoiceSynthesisVO vo){ - String md5Code = vo.md5Code(); - String fileName = String.format("%s.wav",md5Code); - if(Objects.equals(false,this.voiceSynthesisUtil.checkFileIsExist(fileName))){ - byte[] data = voiceService.voiceSynthesis(vo); - this.uploadFile(voiceSynthesisUtil,data,fileName,SYNTHESIS_FOLDER); - } - String filePath = this.voiceSynthesisUtil.getDownLoadPath(fileName); - return new VoiceCompose(filePath,md5Code,vo.getMessage()); - } - - /** - * 语音合成返回原数据 - * @param vo - * @return - */ - public byte[] synthesisSource(BaseVoiceSynthesisVO vo){ - byte[] data = voiceService.voiceSynthesis(vo); - return data; - } - - private void uploadFile(MinioClientUtil minioClient ,byte[] data,String fileName,String folder){ - try{ - minioClient.uploadBytes(data,fileName); - }catch (SimulationException e){ - log.error("文件上传失败 folder:{},文件名:{} errmsg:{}",folder,fileName,e.getMessage(),e); - throw e; - } + private void uploadFile(MinioClientUtil minioClient, byte[] data, String fileName, String folder) { + try { + minioClient.uploadBytes(data, fileName); + } catch (SimulationException e) { + log.error("文件上传失败 folder:{},文件名:{} errmsg:{}", folder, fileName, e.getMessage(), e); + throw e; } + } } diff --git a/src/main/resources/mybatis/mapper/racetr/RacetrTaskDAO.xml b/src/main/resources/mybatis/mapper/racetr/RacetrTaskDAO.xml index 93376c87a..266b5fa83 100644 --- a/src/main/resources/mybatis/mapper/racetr/RacetrTaskDAO.xml +++ b/src/main/resources/mybatis/mapper/racetr/RacetrTaskDAO.xml @@ -330,6 +330,6 @@ UNION all select A.id,A.name,A.desc,A.content,A.standards,A.scene_id,A.score_rule_id as ruleId,A.parent_id from racetr_task A, task B where A.parent_id = B.id) - select A.id,A.name,A.desc,A.content,A.standards,A.score_rule_id as ruleId,A.parent_id,B.id as scene_id,B.type as sceneType from task A left join racetr_scene B on A.scene_id = B.id + select A.id,A.name,A.desc,A.content,A.standards,A.ruleId ,A.parent_id,B.id as scene_id,B.type as sceneType from task A left join racetr_scene B on A.scene_id = B.id \ No newline at end of file