|
@@ -1,12 +1,14 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
import be.tarsos.dsp.AudioDispatcher;
|
|
|
+import be.tarsos.dsp.AudioRunDispatcher;
|
|
|
import be.tarsos.dsp.io.jvm.AudioDispatcherFactory;
|
|
|
import be.tarsos.dsp.pitch.PitchProcessor;
|
|
|
import be.tarsos.dsp.util.PitchConverter;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.ym.mec.biz.dal.config.NioAudioInputStream;
|
|
|
import com.ym.mec.biz.dal.config.SoundCompareConfig;
|
|
|
import com.ym.mec.biz.dal.dao.SysMusicScoreAccompanimentDao;
|
|
|
import com.ym.mec.biz.dal.dto.*;
|
|
@@ -153,6 +155,12 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
userSoundInfoMap.get(phone).setAccessFile(new RandomAccessFile(file, "rw"));
|
|
|
userSoundInfoMap.get(phone).getAccessFile().seek(44);
|
|
|
userSoundInfoMap.get(phone).setRecordFilePath(file.getAbsolutePath());
|
|
|
+
|
|
|
+ AudioRunDispatcher dispatcher = new AudioRunDispatcher(new NioAudioInputStream(userSoundInfoMap.get(phone).getAccessFile(), soundCompareConfig.audioFormat), soundCompareConfig.simpleSize, 0);
|
|
|
+ dispatcher.addAudioProcessor(userSoundInfoMap.get(phone).silenceDetector);
|
|
|
+ dispatcher.addAudioProcessor(new PitchProcessor(soundCompareConfig.algo, soundCompareConfig.simpleRate, soundCompareConfig.simpleSize, userSoundInfoMap.get(phone)));
|
|
|
+// new Thread(dispatcher, phone).start();
|
|
|
+ userSoundInfoMap.get(phone).setAudioRunDispatcher(dispatcher);
|
|
|
} catch (IOException e) {
|
|
|
throw new BizException("文件创建失败:", e);
|
|
|
}
|
|
@@ -226,13 +234,15 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- AudioDispatcher dispatcher = AudioDispatcherFactory.fromByteArray(message.getPayload().array(), soundCompareConfig.audioFormat, soundCompareConfig.simpleSize, soundCompareConfig.overlap);
|
|
|
- dispatcher.addAudioProcessor(userSoundInfoMap.get(phone).silenceDetector);
|
|
|
- dispatcher.addAudioProcessor(new PitchProcessor(soundCompareConfig.algo, soundCompareConfig.simpleRate, soundCompareConfig.simpleSize, userSoundInfoMap.get(phone)));
|
|
|
- dispatcher.run();
|
|
|
+ userSoundInfoMap.get(phone).getAudioRunDispatcher().run();
|
|
|
+
|
|
|
+// AudioDispatcher dispatcher = AudioDispatcherFactory.fromByteArray(message.getPayload().array(), soundCompareConfig.audioFormat, soundCompareConfig.simpleSize, soundCompareConfig.overlap);
|
|
|
+// dispatcher.addAudioProcessor(userSoundInfoMap.get(phone).silenceDetector);
|
|
|
+// dispatcher.addAudioProcessor(new PitchProcessor(soundCompareConfig.algo, soundCompareConfig.simpleRate, soundCompareConfig.simpleSize, userSoundInfoMap.get(phone)));
|
|
|
+// dispatcher.run();
|
|
|
|
|
|
double recordTime = userSoundInfoMap.get(phone).getAccessFile().length()/(soundCompareConfig.audioFormat.getFrameSize()*soundCompareConfig.audioFormat.getFrameRate())*1000;
|
|
|
- userSoundInfoMap.get(phone).setMeasureStartTime(recordTime);
|
|
|
+// userSoundInfoMap.get(phone).setMeasureStartTime(recordTime);
|
|
|
|
|
|
for (Map.Entry<Integer, MusicPitchDetailDto> userMeasureEndTimeMapEntry : userSoundInfoMap.get(phone).getMeasureEndTime().entrySet()) {
|
|
|
if(recordTime>(userMeasureEndTimeMapEntry.getValue().getEndTimeStamp()+100)){
|
|
@@ -245,7 +255,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- } catch (UnsupportedAudioFileException | IOException e) {
|
|
|
+ } catch (IOException e) {
|
|
|
throw new BizException("{}评分异常:{}", phone, e);
|
|
|
}
|
|
|
}
|
|
@@ -293,6 +303,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
randomAccessFile.seek(0);
|
|
|
randomAccessFile.write(WavHeader.getWaveHeader(randomAccessFile.length(), (long) soundCompareConfig.audioFormat.getFrameRate(), soundCompareConfig.audioFormat.getSampleSizeInBits()));
|
|
|
randomAccessFile.close();
|
|
|
+ userSoundInfoMap.get(phone).getAudioRunDispatcher().stop();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|