[修改]语音识别并与正确文本进行校验接口的参数接收方式
All checks were successful
CI / Docker-Build (push) Successful in 2m31s

This commit is contained in:
thesai 2024-05-14 18:32:59 +08:00
parent ba1e057bce
commit 99a772a050
3 changed files with 22 additions and 15 deletions

View File

@ -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);
}
}

View File

@ -21,9 +21,10 @@ public interface IVoiceTrainingService {
/**
* 校验语音识别结果
*
* @param contentType
* @param file 需要校验的语音
* @param text 正确的文本
* @return 校验结果
*/
VoiceVerifyResultVO verifyVoice(MultipartFile file, String text);
VoiceVerifyResultVO verifyVoice(String contentType, byte[] file, String text);
}

View File

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