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; + } }