|
@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.JSONPath;
|
|
|
import com.yonge.audio.analysis.AudioFloatConverter;
|
|
|
import com.yonge.audio.analysis.detector.YINPitchDetector;
|
|
@@ -31,7 +32,7 @@ public class DelayCheckHandler implements MessageHandler {
|
|
|
|
|
|
private final static Logger LOGGER = LoggerFactory.getLogger(DelayCheckHandler.class);
|
|
|
|
|
|
- private final static int MIN_FREQUECY = 3000;
|
|
|
+ private int standardFrequecy = 3000;
|
|
|
|
|
|
/**
|
|
|
* @describe 采样率
|
|
@@ -57,6 +58,8 @@ public class DelayCheckHandler implements MessageHandler {
|
|
|
private AudioFormat audioFormat = new AudioFormat(sampleRate, bitsPerSample, channels, signed, bigEndian);
|
|
|
|
|
|
private AudioFloatConverter converter = AudioFloatConverter.getConverter(audioFormat);
|
|
|
+
|
|
|
+ private boolean isRecWav = false;
|
|
|
|
|
|
private ConcurrentMap<Channel, UserContext> userABCMap = new ConcurrentHashMap<Channel, UserContext>();
|
|
|
|
|
@@ -85,6 +88,13 @@ public class DelayCheckHandler implements MessageHandler {
|
|
|
userContext = new UserContext(0, false);
|
|
|
|
|
|
userABCMap.put(channel, userContext);
|
|
|
+
|
|
|
+ JSONObject dataObj = (JSONObject) JSONPath.extract(jsonMsg, "$.body");
|
|
|
+
|
|
|
+ if(dataObj.get("HZ") != null) {
|
|
|
+ String hzStr = dataObj.get("HZ").toString();
|
|
|
+ standardFrequecy = Integer.parseInt(hzStr);
|
|
|
+ }
|
|
|
|
|
|
break;
|
|
|
case "recordEnd":
|
|
@@ -138,15 +148,17 @@ public class DelayCheckHandler implements MessageHandler {
|
|
|
}
|
|
|
|
|
|
// 写录音文件
|
|
|
- WaveformWriter waveFileProcessor = userContext.getWaveformWriter();
|
|
|
- if (waveFileProcessor == null) {
|
|
|
- File file = new File(tmpFileDir + userId + "_CHECK_" + sdf.format(new Date()) + ".wav");
|
|
|
- waveFileProcessor = new WaveformWriter(file.getAbsolutePath());
|
|
|
- userContext.setWaveformWriter(waveFileProcessor);
|
|
|
-
|
|
|
- userABCMap.put(channel, userContext);
|
|
|
+ if (isRecWav) {
|
|
|
+ WaveformWriter waveFileProcessor = userContext.getWaveformWriter();
|
|
|
+ if (waveFileProcessor == null) {
|
|
|
+ File file = new File(tmpFileDir + userId + "_CHECK_" + sdf.format(new Date()) + ".wav");
|
|
|
+ waveFileProcessor = new WaveformWriter(file.getAbsolutePath());
|
|
|
+ userContext.setWaveformWriter(waveFileProcessor);
|
|
|
+
|
|
|
+ userABCMap.put(channel, userContext);
|
|
|
+ }
|
|
|
+ waveFileProcessor.process(bytes);
|
|
|
}
|
|
|
- waveFileProcessor.process(bytes);
|
|
|
|
|
|
if (userContext.isOver) {
|
|
|
return true;
|
|
@@ -175,20 +187,20 @@ public class DelayCheckHandler implements MessageHandler {
|
|
|
|
|
|
// int amplitude = (int) Signals.decibels(samples);
|
|
|
|
|
|
- if (playFrequency > MIN_FREQUECY) {
|
|
|
-
|
|
|
- userContext.setIsOver(true);
|
|
|
- userABCMap.put(channel, userContext);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
double durationTime = 1000 * (sampleFloats.length * 2) / audioFormat.getSampleRate() / (audioFormat.getSampleSizeInBits() / 8);
|
|
|
|
|
|
double playTime = userContext.delayDuration;
|
|
|
|
|
|
playTime += durationTime;
|
|
|
|
|
|
- System.out.println("DurationTime:"+ durationTime +" playFrequency:" + playFrequency + " PlayTime:" + playTime);
|
|
|
+ LOGGER.info("DurationTime:{} playFrequency:{} PlayTime:{}" ,durationTime,playFrequency,playTime);
|
|
|
+
|
|
|
+ if (playFrequency == standardFrequecy) {
|
|
|
+
|
|
|
+ userContext.setIsOver(true);
|
|
|
+ userABCMap.put(channel, userContext);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
userContext.setDelayDuration(playTime);
|
|
|
|