[新增]语音识别并与正确文本进行校验接口
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.vo.client.PageQueryVO;
|
||||
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.voice.VoiceRecognitionResult;
|
||||
import club.joylink.rtss.vo.voice.VoiceVerifyResultVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
@ -20,34 +21,44 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
@RequestMapping("/api/voice")
|
||||
public class VoiceController {
|
||||
|
||||
@Autowired
|
||||
private IVoiceTrainingService iVoiceTrainingService;
|
||||
@Autowired
|
||||
private IVoiceTrainingService iVoiceTrainingService;
|
||||
|
||||
/**
|
||||
* 语音识别
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("recognition")
|
||||
public VoiceRecognitionResult voiceRecognition(MultipartFile file) {
|
||||
return iVoiceTrainingService.voiceRecognition(file);
|
||||
}
|
||||
/**
|
||||
* 语音识别
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("recognition")
|
||||
public VoiceRecognitionResult voiceRecognition(MultipartFile file) {
|
||||
return iVoiceTrainingService.voiceRecognition(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询语音识别错误集
|
||||
* @param queryVO
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/errorSet/paged")
|
||||
public PageVO<VoiceErrorVO> pagedQueryErrorSet(PageQueryVO queryVO) {
|
||||
return iVoiceTrainingService.pagedQueryErrorSet(queryVO);
|
||||
}
|
||||
/**
|
||||
* 查询语音识别错误集
|
||||
*
|
||||
* @param queryVO
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/errorSet/paged")
|
||||
public PageVO<VoiceErrorVO> pagedQueryErrorSet(PageQueryVO queryVO) {
|
||||
return iVoiceTrainingService.pagedQueryErrorSet(queryVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取百度语音识别token
|
||||
*/
|
||||
@GetMapping("/token/baidu")
|
||||
public String getBaiduToken() {
|
||||
return TokenHolder.getInstance().getToken();
|
||||
}
|
||||
/**
|
||||
* 获取百度语音识别token
|
||||
*/
|
||||
@GetMapping("/token/baidu")
|
||||
public String getBaiduToken() {
|
||||
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.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.client.PageQueryVO;
|
||||
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.VoiceQueryVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
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
|
||||
@RequestMapping("/api/voice/manage")
|
||||
public class VoiceManageController {
|
||||
|
||||
@Autowired
|
||||
private IVoiceDataConfigService configService;
|
||||
@Autowired
|
||||
private IVoiceDataConfigService configService;
|
||||
|
||||
|
||||
@PostMapping("saveOrUpdate")
|
||||
public void saveOrUpdate(@RequestBody VoiceDiscriminateConfigVO configVO, @RequestAttribute(name= AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO userInfoVO) {
|
||||
this.configService.saveOrUpdate(configVO,userInfoVO);
|
||||
}
|
||||
@PostMapping("saveOrUpdate")
|
||||
public void saveOrUpdate(@RequestBody VoiceDiscriminateConfigVO configVO,
|
||||
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO userInfoVO) {
|
||||
this.configService.saveOrUpdate(configVO, userInfoVO);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("find/{id}")
|
||||
public VoiceDiscriminateConfigVO find(@PathVariable(value = "id") Long id) {
|
||||
return this.configService.byId(id);
|
||||
}
|
||||
@GetMapping("find/{id}")
|
||||
public VoiceDiscriminateConfigVO find(@PathVariable(value = "id") Long id) {
|
||||
return this.configService.byId(id);
|
||||
}
|
||||
|
||||
@GetMapping("query")
|
||||
public PageVO<VoiceDiscriminateConfigVO> query(@ModelAttribute VoiceQueryVO queryVO){
|
||||
return this.configService.query(queryVO);
|
||||
}
|
||||
@GetMapping("query")
|
||||
public PageVO<VoiceDiscriminateConfigVO> query(@ModelAttribute VoiceQueryVO queryVO) {
|
||||
return this.configService.query(queryVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取百度语音识别token
|
||||
*/
|
||||
@GetMapping("{id}/{status}")
|
||||
public void changeStatus(@PathVariable(value = "id") Long id,@PathVariable(value = "status")Integer status,@RequestAttribute(name= AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO userInfoVO) {
|
||||
this.configService.changeStatus(id,status,userInfoVO);
|
||||
}
|
||||
/**
|
||||
* 获取百度语音识别token
|
||||
*/
|
||||
@GetMapping("{id}/{status}")
|
||||
public void changeStatus(@PathVariable(value = "id") Long id,
|
||||
@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.competition.VoiceErrorVO;
|
||||
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
|
||||
import club.joylink.rtss.vo.voice.VoiceVerifyResultVO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
|
@ -11,9 +12,18 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
*/
|
||||
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.entity.CompetitionErrorSet;
|
||||
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.PageVO;
|
||||
import club.joylink.rtss.vo.client.competition.VoiceErrorVO;
|
||||
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
|
||||
import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO;
|
||||
import club.joylink.rtss.vo.voice.VoiceVerifyResultVO;
|
||||
import com.github.pagehelper.Page;
|
||||
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.stream.Collectors;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
public class VoiceTrainingService implements IVoiceTrainingService {
|
||||
|
||||
@Autowired
|
||||
private CompetitionErrorSetDAO competitionErrorSetDAO;
|
||||
@Autowired
|
||||
private CompetitionErrorSetDAO competitionErrorSetDAO;
|
||||
|
||||
/* @Autowired
|
||||
@Qualifier("baiDuVoiceService")
|
||||
private IVoiceService iVoiceService;*/
|
||||
|
||||
@Autowired
|
||||
@Autowired
|
||||
// @Qualifier("baiDuVoiceService2")
|
||||
private VoiceService iVoiceService;
|
||||
private VoiceService iVoiceService;
|
||||
|
||||
@Autowired
|
||||
private SimulationVoiceHandler simulationVoiceHandler;
|
||||
@Autowired
|
||||
private SimulationVoiceHandler simulationVoiceHandler;
|
||||
|
||||
|
||||
@Override
|
||||
public PageVO<VoiceErrorVO> pagedQueryErrorSet(PageQueryVO queryVO) {
|
||||
Page<Object> page = PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
|
||||
List<CompetitionErrorSet> sets = competitionErrorSetDAO.selectByExample(null);
|
||||
List<VoiceErrorVO> list = sets.stream().map(VoiceErrorVO::new).collect(Collectors.toList());
|
||||
return PageVO.convert(page, list);
|
||||
}
|
||||
@Override
|
||||
public PageVO<VoiceErrorVO> pagedQueryErrorSet(PageQueryVO queryVO) {
|
||||
Page<Object> page = PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
|
||||
List<CompetitionErrorSet> sets = competitionErrorSetDAO.selectByExample(null);
|
||||
List<VoiceErrorVO> list = sets.stream().map(VoiceErrorVO::new).collect(Collectors.toList());
|
||||
return PageVO.convert(page, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoiceRecognitionResult voiceRecognition(MultipartFile file) {
|
||||
VoiceRecognitionVO vo = VoiceRecognitionVO.load(file);
|
||||
VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(vo);
|
||||
@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;
|
||||
}
|
||||
result.setResult(simulationVoiceHandler.handle(result.getResult()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoiceRecognitionResult voiceRecognition(byte[] bytes, String filePath) {
|
||||
VoiceRecognitionVO vo = new VoiceRecognitionVO(bytes);
|
||||
VoiceRecognitionResult result = this.iVoiceService.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;
|
||||
}
|
||||
result.setResult(simulationVoiceHandler.handle(result.getResult()));
|
||||
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