From 99a772a050971e89628e8eb2cf1f65a449a7a3f1 Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Tue, 14 May 2024 18:32:59 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E6=94=B9]=E8=AF=AD=E9=9F=B3=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E5=B9=B6=E4=B8=8E=E6=AD=A3=E7=A1=AE=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=A0=A1=E9=AA=8C=E6=8E=A5=E5=8F=A3=E7=9A=84?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=8E=A5=E6=94=B6=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/voice/VoiceController.java | 8 +++++-- .../services/voice/IVoiceTrainingService.java | 7 +++--- .../services/voice/VoiceTrainingService.java | 22 ++++++++++--------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/main/java/club/joylink/rtss/controller/voice/VoiceController.java b/src/main/java/club/joylink/rtss/controller/voice/VoiceController.java index b91276d67..54cd22634 100644 --- a/src/main/java/club/joylink/rtss/controller/voice/VoiceController.java +++ b/src/main/java/club/joylink/rtss/controller/voice/VoiceController.java @@ -7,9 +7,11 @@ import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.competition.VoiceErrorVO; import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult; import club.joylink.rtss.vo.voice.VoiceVerifyResultVO; +import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @@ -58,7 +60,9 @@ public class VoiceController { * 校验语音识别结果 */ @PostMapping("/verify") - public VoiceVerifyResultVO verifyVoice(MultipartFile file, String text) { - return iVoiceTrainingService.verifyVoice(file, text); + public VoiceVerifyResultVO verifyVoice(HttpServletRequest request, @RequestBody byte[] fileData, + String text) { + String contentType = request.getHeader("Content-Type"); + return iVoiceTrainingService.verifyVoice(contentType, fileData, text); } } diff --git a/src/main/java/club/joylink/rtss/services/voice/IVoiceTrainingService.java b/src/main/java/club/joylink/rtss/services/voice/IVoiceTrainingService.java index f99e6158a..ce45089f5 100644 --- a/src/main/java/club/joylink/rtss/services/voice/IVoiceTrainingService.java +++ b/src/main/java/club/joylink/rtss/services/voice/IVoiceTrainingService.java @@ -21,9 +21,10 @@ public interface IVoiceTrainingService { /** * 校验语音识别结果 * - * @param file 需要校验的语音 - * @param text 正确的文本 + * @param contentType + * @param file 需要校验的语音 + * @param text 正确的文本 * @return 校验结果 */ - VoiceVerifyResultVO verifyVoice(MultipartFile file, String text); + VoiceVerifyResultVO verifyVoice(String contentType, byte[] file, String text); } diff --git a/src/main/java/club/joylink/rtss/services/voice/VoiceTrainingService.java b/src/main/java/club/joylink/rtss/services/voice/VoiceTrainingService.java index 45770181d..0520097b2 100644 --- a/src/main/java/club/joylink/rtss/services/voice/VoiceTrainingService.java +++ b/src/main/java/club/joylink/rtss/services/voice/VoiceTrainingService.java @@ -47,25 +47,27 @@ public class VoiceTrainingService implements IVoiceTrainingService { @Override public VoiceRecognitionResult voiceRecognition(MultipartFile file) { VoiceRecognitionVO vo = VoiceRecognitionVO.load(file); - VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(vo); -// VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(file, ""); - result.setResult(simulationVoiceHandler.handle(result.getResult())); - return result; + return voiceRecognition(vo); } @Override public VoiceRecognitionResult voiceRecognition(byte[] bytes, String filePath) { VoiceRecognitionVO vo = new VoiceRecognitionVO(bytes); - VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(vo); -// VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(bytes, filePath); - result.setResult(simulationVoiceHandler.handle(result.getResult())); - return result; + return voiceRecognition(vo); } @Override - public VoiceVerifyResultVO verifyVoice(MultipartFile file, String text) { - VoiceRecognitionResult voiceRecognitionResult = voiceRecognition(file); + public VoiceVerifyResultVO verifyVoice(String contentType, byte[] fileData, String text) { + VoiceRecognitionResult voiceRecognitionResult = voiceRecognition( + new VoiceRecognitionVO(fileData, contentType)); boolean match = StrUtils.isMatch(text, voiceRecognitionResult.getResult(), 20); return new VoiceVerifyResultVO(voiceRecognitionResult.getResult(), match); } + + private VoiceRecognitionResult voiceRecognition(VoiceRecognitionVO vo) { + VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(vo); +// VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(file, ""); + result.setResult(simulationVoiceHandler.handle(result.getResult())); + return result; + } }