Browse Source

feat:小节评分

Joburgess 4 năm trước cách đây
mục cha
commit
16024ff340

+ 9 - 7
mec-teacher/src/main/java/com/ym/mec/teacher/handler/WebSocketHandler.java

@@ -10,6 +10,7 @@ import com.ym.mec.biz.dal.dto.WavHeader;
 import com.ym.mec.biz.dal.dto.WebSocketInfo;
 import com.ym.mec.biz.service.SoundSocketService;
 import com.ym.mec.common.constant.CommonConstants;
+import org.apache.commons.io.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -44,6 +45,8 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
     AudioFormat audioFormat = new AudioFormat(44100, 16, 1, true, false);
     PitchProcessor.PitchEstimationAlgorithm algo = PitchProcessor.PitchEstimationAlgorithm.FFT_YIN;
 
+    private String tmpDir = FileUtils.getTempDirectoryPath() + "/soundCompare/";
+
     private Map<String, RandomAccessFile> userRandomAccessFileMap = new ConcurrentHashMap<>();
     private Map<String, Map<Integer, List<MusicPitchDetailDto>>> userMeasureXmlInfoMap = new ConcurrentHashMap<>();
     private Map<String, Map<Integer, Integer>> userMeasureEndTimeMap = new ConcurrentHashMap<>();
@@ -94,7 +97,7 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
                 }
                 break;
             case SoundSocketService.RECORD_START:
-                File file = new File("E:\\Temp\\record"+phone +"-"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) +".wav");
+                File file = new File(tmpDir+phone +"-"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) +".wav");
                 userRandomAccessFileMap.put(phone, new RandomAccessFile(file, "rw"));
                 userMeasureMap.put(phone, new HashSet<>());
                 userMeasureStartTimeMap.put(phone, (double) 0);
@@ -204,7 +207,7 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
             //音准匹配数量
             float intonationNum = 0;
             //音准匹配误差范围
-            float intonationErrRange = 10;
+            float intonationErrRange = 100;
             //音准有效阈值
             float intonationValidDuty = 0.8f;
 
@@ -291,7 +294,7 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
         }else{
             userTotalScoreMap.get(phone).put("integrity", integrity);
         }
-        WS_CLIENTS.get(phone).sendMessage(new TextMessage(JSON.toJSONString(createPushInfo("measureScore", measureIndex, score, intonation, cadence, integrity))));
+        WS_CLIENTS.get(phone).sendMessage(new TextMessage(JSON.toJSONString(createPushInfo("measureScore", measureIndex, intonation, cadence, integrity))));
 //                LOGGER.info("推送评分结果:{}", phone);
     }
 
@@ -300,19 +303,18 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
         BigDecimal intonation = userTotalScoreMap.get(phone).get("intonation").divide(new BigDecimal(totalCompareNum), 0, BigDecimal.ROUND_DOWN);
         BigDecimal cadence = userTotalScoreMap.get(phone).get("cadence").divide(new BigDecimal(totalCompareNum), 0, BigDecimal.ROUND_DOWN);
         BigDecimal integrity = userTotalScoreMap.get(phone).get("integrity").divide(new BigDecimal(totalCompareNum), 0, BigDecimal.ROUND_DOWN);
-        BigDecimal score = intonation.multiply(new BigDecimal(0.9)).add(cadence.multiply(new BigDecimal(0.9))).add(integrity.multiply(new BigDecimal(0.1))).setScale(0, BigDecimal.ROUND_HALF_UP);
 
-        WS_CLIENTS.get(phone).sendMessage(new TextMessage(JSON.toJSONString(createPushInfo("overall", -1, score, intonation, cadence, integrity))));
-        LOGGER.info("录音频率信息:{}", JSON.toJSONString(userLastMeasurePithInfoMap));
+        WS_CLIENTS.get(phone).sendMessage(new TextMessage(JSON.toJSONString(createPushInfo("overall", -1, intonation, cadence, integrity))));
     }
 
     private WebSocketInfo createPushInfo(String commond, Integer measureIndex,
-                                         BigDecimal score, BigDecimal intonation, BigDecimal cadence, BigDecimal integrity){
+                                         BigDecimal intonation, BigDecimal cadence, BigDecimal integrity){
         WebSocketInfo webSocketInfo = new WebSocketInfo();
         HashMap<String, String> header = new HashMap<>();
         header.put("commond", commond);
         webSocketInfo.setHeader(header);
         Map<String, Object> result = new HashMap<>();
+        BigDecimal score = intonation.multiply(new BigDecimal(0.45)).add(cadence.multiply(new BigDecimal(0.45))).add(integrity.multiply(new BigDecimal(0.1))).setScale(0, BigDecimal.ROUND_HALF_UP);
         result.put("score", score);
         result.put("intonation", intonation);
         result.put("cadence", cadence);