|
@@ -42,6 +42,8 @@ public class SoundCheckHandler implements WebSocketEventHandler {
|
|
|
|
|
|
private final Logger LOGGER = LoggerFactory.getLogger(SoundCheckHandler.class);
|
|
|
|
|
|
+ private final int SIZE = 264600;
|
|
|
+
|
|
|
/** 校音数据 */
|
|
|
private Map<String, SoundCheckHelper> userSoundCheckInfo = new ConcurrentHashMap<>();
|
|
|
|
|
@@ -61,7 +63,7 @@ public class SoundCheckHandler implements WebSocketEventHandler {
|
|
|
userSoundCheckInfo.remove(phone);
|
|
|
break;
|
|
|
default:
|
|
|
- userSoundCheckInfo.put(phone, new SoundCheckHelper(442, 0));
|
|
|
+ userSoundCheckInfo.put(phone, new SoundCheckHelper(442));
|
|
|
JSONObject body = (JSONObject) message.getBody();
|
|
|
if(body.containsKey("frequency")){
|
|
|
userSoundCheckInfo.get(phone).setFrequency(body.getDoubleValue("frequency"));
|
|
@@ -86,8 +88,8 @@ public class SoundCheckHandler implements WebSocketEventHandler {
|
|
|
}
|
|
|
double normalCents = PitchConverter.hertzToAbsoluteCent(userSoundCheckInfo.get(phone).getFrequency());
|
|
|
double recordCents = PitchConverter.hertzToAbsoluteCent(pitchDetectionResult.getPitch());
|
|
|
- if(Math.abs(normalCents - recordCents)<3 && userSoundCheckInfo.get(phone).getRightStartTime()<=0){
|
|
|
- userSoundCheckInfo.get(phone).setRightStartTime(System.currentTimeMillis());
|
|
|
+ if(Math.abs(normalCents - recordCents)<3){
|
|
|
+ userSoundCheckInfo.get(phone).setRightSize(userSoundCheckInfo.get(phone).getRightSize() + audioEvent.getBufferSize());
|
|
|
userSoundCheckInfo.get(phone).getErrorNum().set(0);
|
|
|
}else if(Math.abs(normalCents - recordCents)>=3){
|
|
|
userSoundCheckInfo.get(phone).getErrorNum().getAndIncrement();
|
|
@@ -95,11 +97,11 @@ public class SoundCheckHandler implements WebSocketEventHandler {
|
|
|
}));
|
|
|
dispatcher.run();
|
|
|
LOGGER.info(JSONObject.toJSONString(userSoundCheckInfo.get(phone)));
|
|
|
- if(userSoundCheckInfo.get(phone).getRightStartTime() >0 && System.currentTimeMillis() - userSoundCheckInfo.get(phone).getRightStartTime()>3000){
|
|
|
+ if(userSoundCheckInfo.get(phone).getRightSize()>SIZE){
|
|
|
WebSocketHandler.sendTextMessage(phone, WebSocketInfo.success("checkDone"));
|
|
|
userSoundCheckInfo.remove(phone);
|
|
|
}else if(userSoundCheckInfo.get(phone).getErrorNum().get()>5){
|
|
|
- userSoundCheckInfo.get(phone).setRightStartTime(0);
|
|
|
+ userSoundCheckInfo.get(phone).setRightSize(0);
|
|
|
}
|
|
|
} catch (UnsupportedAudioFileException e) {
|
|
|
throw new BizException("{}校音异常:{}", phone, e);
|