|  | @@ -2,11 +2,9 @@ package com.ym.mec.teacher.handler;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import be.tarsos.dsp.AudioDispatcher;
 | 
	
		
			
				|  |  |  import be.tarsos.dsp.io.jvm.AudioDispatcherFactory;
 | 
	
		
			
				|  |  | -import be.tarsos.dsp.io.jvm.JVMAudioInputStream;
 | 
	
		
			
				|  |  |  import be.tarsos.dsp.pitch.PitchProcessor;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dto.AudioRecordConfig;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.MusicPitchDetailDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.WavHeader;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.WebSocketInfo;
 | 
	
	
		
			
				|  | @@ -19,15 +17,11 @@ import org.springframework.web.socket.*;
 | 
	
		
			
				|  |  |  import org.springframework.web.socket.handler.AbstractWebSocketHandler;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.sound.sampled.AudioFormat;
 | 
	
		
			
				|  |  | -import javax.sound.sampled.AudioInputStream;
 | 
	
		
			
				|  |  | -import javax.sound.sampled.DataLine;
 | 
	
		
			
				|  |  | -import javax.sound.sampled.TargetDataLine;
 | 
	
		
			
				|  |  |  import java.io.*;
 | 
	
		
			
				|  |  |  import java.time.LocalDateTime;
 | 
	
		
			
				|  |  |  import java.time.format.DateTimeFormatter;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  import java.util.concurrent.ConcurrentHashMap;
 | 
	
		
			
				|  |  | -import java.util.concurrent.atomic.AtomicReference;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * @Author Joburgess
 | 
	
	
		
			
				|  | @@ -104,11 +98,11 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
 | 
	
		
			
				|  |  |          dispatcher.addAudioProcessor(new PitchProcessor(algo, 44100, 256, (pitchDetectionResult, audioEvent) -> {
 | 
	
		
			
				|  |  |              double timeStamp = audioEvent.getTimeStamp();
 | 
	
		
			
				|  |  |              float pitch = pitchDetectionResult.getPitch();
 | 
	
		
			
				|  |  | -            LOGGER.info("时间:{},频率:{}", timeStamp, pitch);
 | 
	
		
			
				|  |  | +//            LOGGER.info("时间:{},频率:{}", timeStamp, pitch);
 | 
	
		
			
				|  |  |          }));
 | 
	
		
			
				|  |  |          dispatcher.run();
 | 
	
		
			
				|  |  |          double recordTime = userRandomAccessFileMap.get(phone).length()/(audioFormat.getFrameSize()*audioFormat.getFrameRate())*1000;
 | 
	
		
			
				|  |  | -        LOGGER.info("时长:{}", recordTime);
 | 
	
		
			
				|  |  | +//        LOGGER.info("时长:{}", recordTime);
 | 
	
		
			
				|  |  |          for (MusicPitchDetailDto musicPitchDetailDto : userXmlInfoMap.get(phone)) {
 | 
	
		
			
				|  |  |              if(!userMeasureMap.get(phone).contains(musicPitchDetailDto.getMeasureIndex())&&recordTime>musicPitchDetailDto.getTimeStamp()+musicPitchDetailDto.getDuration()){
 | 
	
		
			
				|  |  |                  WebSocketInfo webSocketInfo = new WebSocketInfo();
 | 
	
	
		
			
				|  | @@ -125,6 +119,7 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
 | 
	
		
			
				|  |  |                  webSocketInfo.setBody(result);
 | 
	
		
			
				|  |  |                  WS_CLIENTS.get(phone).sendMessage(new TextMessage(JSON.toJSONString(webSocketInfo)));
 | 
	
		
			
				|  |  |                  userMeasureMap.get(phone).add(musicPitchDetailDto.getMeasureIndex());
 | 
	
		
			
				|  |  | +                LOGGER.info("推送评分结果:{}", phone);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -165,8 +160,9 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          RandomAccessFile randomAccessFile = userRandomAccessFileMap.get(phone);
 | 
	
		
			
				|  |  | +        LOGGER.info("音频时长:{}", randomAccessFile.length()/(audioFormat.getFrameSize()*audioFormat.getFrameRate())*1000);
 | 
	
		
			
				|  |  |          randomAccessFile.seek(0);
 | 
	
		
			
				|  |  | -        randomAccessFile.write(new WavHeader(new AudioRecordConfig(), randomAccessFile.length()).toBytes());
 | 
	
		
			
				|  |  | +        randomAccessFile.write(WavHeader.getWaveHeader(randomAccessFile.length(), (long) audioFormat.getFrameRate(), audioFormat.getSampleSizeInBits()));
 | 
	
		
			
				|  |  |          randomAccessFile.close();
 | 
	
		
			
				|  |  |          userRandomAccessFileMap.remove(phone);
 | 
	
		
			
				|  |  |      }
 |