[新增]语音识别并与正确文本进行校验接口
CI / Docker-Build (push) Successful in 8m28s
Details
CI / Docker-Build (push) Successful in 8m28s
Details
This commit is contained in:
parent
6187e6d667
commit
ba1e057bce
|
@ -4,8 +4,9 @@ import club.joylink.rtss.services.voice.IVoiceTrainingService;
|
||||||
import club.joylink.rtss.services.voice.baidu.TokenHolder;
|
import club.joylink.rtss.services.voice.baidu.TokenHolder;
|
||||||
import club.joylink.rtss.vo.client.PageQueryVO;
|
import club.joylink.rtss.vo.client.PageQueryVO;
|
||||||
import club.joylink.rtss.vo.client.PageVO;
|
import club.joylink.rtss.vo.client.PageVO;
|
||||||
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
|
|
||||||
import club.joylink.rtss.vo.client.competition.VoiceErrorVO;
|
import club.joylink.rtss.vo.client.competition.VoiceErrorVO;
|
||||||
|
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
|
||||||
|
import club.joylink.rtss.vo.voice.VoiceVerifyResultVO;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
@ -20,34 +21,44 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
@RequestMapping("/api/voice")
|
@RequestMapping("/api/voice")
|
||||||
public class VoiceController {
|
public class VoiceController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IVoiceTrainingService iVoiceTrainingService;
|
private IVoiceTrainingService iVoiceTrainingService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 语音识别
|
* 语音识别
|
||||||
* @param file
|
*
|
||||||
* @return
|
* @param file
|
||||||
*/
|
* @return
|
||||||
@PostMapping("recognition")
|
*/
|
||||||
public VoiceRecognitionResult voiceRecognition(MultipartFile file) {
|
@PostMapping("recognition")
|
||||||
return iVoiceTrainingService.voiceRecognition(file);
|
public VoiceRecognitionResult voiceRecognition(MultipartFile file) {
|
||||||
}
|
return iVoiceTrainingService.voiceRecognition(file);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询语音识别错误集
|
* 查询语音识别错误集
|
||||||
* @param queryVO
|
*
|
||||||
* @return
|
* @param queryVO
|
||||||
*/
|
* @return
|
||||||
@GetMapping("/errorSet/paged")
|
*/
|
||||||
public PageVO<VoiceErrorVO> pagedQueryErrorSet(PageQueryVO queryVO) {
|
@GetMapping("/errorSet/paged")
|
||||||
return iVoiceTrainingService.pagedQueryErrorSet(queryVO);
|
public PageVO<VoiceErrorVO> pagedQueryErrorSet(PageQueryVO queryVO) {
|
||||||
}
|
return iVoiceTrainingService.pagedQueryErrorSet(queryVO);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取百度语音识别token
|
* 获取百度语音识别token
|
||||||
*/
|
*/
|
||||||
@GetMapping("/token/baidu")
|
@GetMapping("/token/baidu")
|
||||||
public String getBaiduToken() {
|
public String getBaiduToken() {
|
||||||
return TokenHolder.getInstance().getToken();
|
return TokenHolder.getInstance().getToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验语音识别结果
|
||||||
|
*/
|
||||||
|
@PostMapping("/verify")
|
||||||
|
public VoiceVerifyResultVO verifyVoice(MultipartFile file, String text) {
|
||||||
|
return iVoiceTrainingService.verifyVoice(file, text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,51 +2,55 @@ package club.joylink.rtss.controller.voice;
|
||||||
|
|
||||||
import club.joylink.rtss.controller.advice.AuthenticateInterceptor;
|
import club.joylink.rtss.controller.advice.AuthenticateInterceptor;
|
||||||
import club.joylink.rtss.services.voice.IVoiceDataConfigService;
|
import club.joylink.rtss.services.voice.IVoiceDataConfigService;
|
||||||
import club.joylink.rtss.services.voice.IVoiceTrainingService;
|
|
||||||
import club.joylink.rtss.services.voice.baidu.TokenHolder;
|
|
||||||
import club.joylink.rtss.vo.LoginUserInfoVO;
|
import club.joylink.rtss.vo.LoginUserInfoVO;
|
||||||
import club.joylink.rtss.vo.client.PageQueryVO;
|
|
||||||
import club.joylink.rtss.vo.client.PageVO;
|
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.VoiceDiscriminateConfigVO;
|
import club.joylink.rtss.vo.voice.VoiceDiscriminateConfigVO;
|
||||||
import club.joylink.rtss.vo.voice.VoiceQueryVO;
|
import club.joylink.rtss.vo.voice.VoiceQueryVO;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 语音AI接口
|
* 语音管理接口
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/voice/manage")
|
@RequestMapping("/api/voice/manage")
|
||||||
public class VoiceManageController {
|
public class VoiceManageController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IVoiceDataConfigService configService;
|
private IVoiceDataConfigService configService;
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("saveOrUpdate")
|
@PostMapping("saveOrUpdate")
|
||||||
public void saveOrUpdate(@RequestBody VoiceDiscriminateConfigVO configVO, @RequestAttribute(name= AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO userInfoVO) {
|
public void saveOrUpdate(@RequestBody VoiceDiscriminateConfigVO configVO,
|
||||||
this.configService.saveOrUpdate(configVO,userInfoVO);
|
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO userInfoVO) {
|
||||||
}
|
this.configService.saveOrUpdate(configVO, userInfoVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("find/{id}")
|
@GetMapping("find/{id}")
|
||||||
public VoiceDiscriminateConfigVO find(@PathVariable(value = "id") Long id) {
|
public VoiceDiscriminateConfigVO find(@PathVariable(value = "id") Long id) {
|
||||||
return this.configService.byId(id);
|
return this.configService.byId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("query")
|
@GetMapping("query")
|
||||||
public PageVO<VoiceDiscriminateConfigVO> query(@ModelAttribute VoiceQueryVO queryVO){
|
public PageVO<VoiceDiscriminateConfigVO> query(@ModelAttribute VoiceQueryVO queryVO) {
|
||||||
return this.configService.query(queryVO);
|
return this.configService.query(queryVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取百度语音识别token
|
* 获取百度语音识别token
|
||||||
*/
|
*/
|
||||||
@GetMapping("{id}/{status}")
|
@GetMapping("{id}/{status}")
|
||||||
public void changeStatus(@PathVariable(value = "id") Long id,@PathVariable(value = "status")Integer status,@RequestAttribute(name= AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO userInfoVO) {
|
public void changeStatus(@PathVariable(value = "id") Long id,
|
||||||
this.configService.changeStatus(id,status,userInfoVO);
|
@PathVariable(value = "status") Integer status,
|
||||||
}
|
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO userInfoVO) {
|
||||||
|
this.configService.changeStatus(id, status, userInfoVO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import club.joylink.rtss.vo.client.PageQueryVO;
|
||||||
import club.joylink.rtss.vo.client.PageVO;
|
import club.joylink.rtss.vo.client.PageVO;
|
||||||
import club.joylink.rtss.vo.client.competition.VoiceErrorVO;
|
import club.joylink.rtss.vo.client.competition.VoiceErrorVO;
|
||||||
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
|
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
|
||||||
|
import club.joylink.rtss.vo.voice.VoiceVerifyResultVO;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,9 +12,18 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
*/
|
*/
|
||||||
public interface IVoiceTrainingService {
|
public interface IVoiceTrainingService {
|
||||||
|
|
||||||
PageVO<VoiceErrorVO> pagedQueryErrorSet(PageQueryVO queryVO);
|
PageVO<VoiceErrorVO> pagedQueryErrorSet(PageQueryVO queryVO);
|
||||||
|
|
||||||
VoiceRecognitionResult voiceRecognition(MultipartFile file);
|
VoiceRecognitionResult voiceRecognition(MultipartFile file);
|
||||||
|
|
||||||
VoiceRecognitionResult voiceRecognition(byte[] bytes, String filePath);
|
VoiceRecognitionResult voiceRecognition(byte[] bytes, String filePath);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验语音识别结果
|
||||||
|
*
|
||||||
|
* @param file 需要校验的语音
|
||||||
|
* @param text 正确的文本
|
||||||
|
* @return 校验结果
|
||||||
|
*/
|
||||||
|
VoiceVerifyResultVO verifyVoice(MultipartFile file, String text);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,62 +3,69 @@ package club.joylink.rtss.services.voice;
|
||||||
import club.joylink.rtss.dao.CompetitionErrorSetDAO;
|
import club.joylink.rtss.dao.CompetitionErrorSetDAO;
|
||||||
import club.joylink.rtss.entity.CompetitionErrorSet;
|
import club.joylink.rtss.entity.CompetitionErrorSet;
|
||||||
import club.joylink.rtss.simulation.cbtc.conversation.SimulationVoiceHandler;
|
import club.joylink.rtss.simulation.cbtc.conversation.SimulationVoiceHandler;
|
||||||
|
import club.joylink.rtss.util.StrUtils;
|
||||||
import club.joylink.rtss.vo.client.PageQueryVO;
|
import club.joylink.rtss.vo.client.PageQueryVO;
|
||||||
import club.joylink.rtss.vo.client.PageVO;
|
import club.joylink.rtss.vo.client.PageVO;
|
||||||
import club.joylink.rtss.vo.client.competition.VoiceErrorVO;
|
import club.joylink.rtss.vo.client.competition.VoiceErrorVO;
|
||||||
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
|
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
|
||||||
import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO;
|
import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO;
|
||||||
|
import club.joylink.rtss.vo.voice.VoiceVerifyResultVO;
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class VoiceTrainingService implements IVoiceTrainingService {
|
public class VoiceTrainingService implements IVoiceTrainingService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CompetitionErrorSetDAO competitionErrorSetDAO;
|
private CompetitionErrorSetDAO competitionErrorSetDAO;
|
||||||
|
|
||||||
/* @Autowired
|
/* @Autowired
|
||||||
@Qualifier("baiDuVoiceService")
|
@Qualifier("baiDuVoiceService")
|
||||||
private IVoiceService iVoiceService;*/
|
private IVoiceService iVoiceService;*/
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
// @Qualifier("baiDuVoiceService2")
|
// @Qualifier("baiDuVoiceService2")
|
||||||
private VoiceService iVoiceService;
|
private VoiceService iVoiceService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SimulationVoiceHandler simulationVoiceHandler;
|
private SimulationVoiceHandler simulationVoiceHandler;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageVO<VoiceErrorVO> pagedQueryErrorSet(PageQueryVO queryVO) {
|
public PageVO<VoiceErrorVO> pagedQueryErrorSet(PageQueryVO queryVO) {
|
||||||
Page<Object> page = PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
|
Page<Object> page = PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
|
||||||
List<CompetitionErrorSet> sets = competitionErrorSetDAO.selectByExample(null);
|
List<CompetitionErrorSet> sets = competitionErrorSetDAO.selectByExample(null);
|
||||||
List<VoiceErrorVO> list = sets.stream().map(VoiceErrorVO::new).collect(Collectors.toList());
|
List<VoiceErrorVO> list = sets.stream().map(VoiceErrorVO::new).collect(Collectors.toList());
|
||||||
return PageVO.convert(page, list);
|
return PageVO.convert(page, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VoiceRecognitionResult voiceRecognition(MultipartFile file) {
|
public VoiceRecognitionResult voiceRecognition(MultipartFile file) {
|
||||||
VoiceRecognitionVO vo = VoiceRecognitionVO.load(file);
|
VoiceRecognitionVO vo = VoiceRecognitionVO.load(file);
|
||||||
VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(vo);
|
VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(vo);
|
||||||
// VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(file, "");
|
// VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(file, "");
|
||||||
result.setResult(simulationVoiceHandler.handle(result.getResult()));
|
result.setResult(simulationVoiceHandler.handle(result.getResult()));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VoiceRecognitionResult voiceRecognition(byte[] bytes, String filePath) {
|
public VoiceRecognitionResult voiceRecognition(byte[] bytes, String filePath) {
|
||||||
VoiceRecognitionVO vo = new VoiceRecognitionVO(bytes);
|
VoiceRecognitionVO vo = new VoiceRecognitionVO(bytes);
|
||||||
VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(vo);
|
VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(vo);
|
||||||
// VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(bytes, filePath);
|
// VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(bytes, filePath);
|
||||||
result.setResult(simulationVoiceHandler.handle(result.getResult()));
|
result.setResult(simulationVoiceHandler.handle(result.getResult()));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VoiceVerifyResultVO verifyVoice(MultipartFile file, String text) {
|
||||||
|
VoiceRecognitionResult voiceRecognitionResult = voiceRecognition(file);
|
||||||
|
boolean match = StrUtils.isMatch(text, voiceRecognitionResult.getResult(), 20);
|
||||||
|
return new VoiceVerifyResultVO(voiceRecognitionResult.getResult(), match);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package club.joylink.rtss.vo.voice;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class VoiceVerifyResultVO {
|
||||||
|
|
||||||
|
private String text;
|
||||||
|
|
||||||
|
private boolean match;
|
||||||
|
}
|
Loading…
Reference in New Issue