|
@@ -83,7 +83,6 @@ public class SoundServiceImpl implements SoundService {
|
|
|
List<Double> pitchs = new ArrayList<>();
|
|
|
int size = 2048;
|
|
|
int overlap = 0;
|
|
|
- Double[] t = new Double[1];
|
|
|
final SilenceDetector silenceDetecor = new SilenceDetector();
|
|
|
AudioDispatcher dispatcher = StringUtils.isBlank(url)?getFromByteArray(bytes, size, overlap):getFromFile(url, size, overlap);
|
|
|
dispatcher.addAudioProcessor(silenceDetecor);
|
|
@@ -95,13 +94,11 @@ public class SoundServiceImpl implements SoundService {
|
|
|
|
|
|
@Override
|
|
|
public boolean process(AudioEvent audioEvent) {
|
|
|
- t[0] = audioEvent.getEndTimeStamp();
|
|
|
pitchs.add(Double.isInfinite(silenceDetecor.currentSPL())?0:silenceDetecor.currentSPL());
|
|
|
return true;
|
|
|
}
|
|
|
});
|
|
|
dispatcher.run();
|
|
|
- pitchs.add(t[0]);
|
|
|
return pitchs;
|
|
|
}
|
|
|
|
|
@@ -130,29 +127,32 @@ public class SoundServiceImpl implements SoundService {
|
|
|
}
|
|
|
Map<String, BigDecimal> result = new HashMap<>();
|
|
|
|
|
|
+ LOGGER.info("录音文件大小:{}MB,伴奏编号:{},源文件:{}", record.getSize()/1048576f, musicScoreId, sysMusicScore.getUrl());
|
|
|
+ String tmpDir = FileUtils.getTempDirectoryPath() + "/";
|
|
|
+
|
|
|
+ BigDecimal oneHandred = new BigDecimal(100);
|
|
|
+ //总分
|
|
|
BigDecimal score = BigDecimal.ZERO;
|
|
|
+ //相似度
|
|
|
BigDecimal intonation = BigDecimal.ZERO;
|
|
|
+ //节奏
|
|
|
BigDecimal cadence = BigDecimal.ZERO;
|
|
|
+ //完整度
|
|
|
BigDecimal integrity = BigDecimal.ZERO;
|
|
|
File f = null;
|
|
|
File f_r = null;
|
|
|
try {
|
|
|
+ //存储录音文件
|
|
|
+ String filePath_r = tmpDir + idGeneratorService.generatorId("sound") + "_r.wav";
|
|
|
+ f_r = new File(filePath_r);
|
|
|
+ FileUtils.copyToFile(record.getInputStream(), f_r);
|
|
|
+
|
|
|
+ //下载原音文件
|
|
|
URL url = new URL(sysMusicScore.getUrl());
|
|
|
- String filePath = FileUtils.getTempDirectoryPath()+ idGeneratorService.generatorId("sound") + ".mp3";
|
|
|
+ String filePath = tmpDir + idGeneratorService.generatorId("sound") + "_s.mp3";
|
|
|
f = new File(filePath);
|
|
|
FileUtils.copyURLToFile(url, f);
|
|
|
|
|
|
- LOGGER.info("录音文件大小:{}MB,伴奏编号:{},源文件:{}", record.getSize()/1048576f, musicScoreId, filePath);
|
|
|
-
|
|
|
- BigDecimal oneHandred = new BigDecimal(100);
|
|
|
-
|
|
|
- BigDecimal l_s = new BigDecimal(0);
|
|
|
- BigDecimal l_r = new BigDecimal(0);
|
|
|
-
|
|
|
- String filePath_r = FileUtils.getTempDirectoryPath()+ idGeneratorService.generatorId("sound") + "_r.wav";
|
|
|
- f_r = new File(filePath_r);
|
|
|
- FileUtils.copyToFile(record.getInputStream(), f_r);
|
|
|
-
|
|
|
//相似度
|
|
|
List<Double> pitchs_s = soundPressureLevelExtractor(null, filePath);
|
|
|
List<Double> pitchs_r = soundPressureLevelExtractor(null, filePath_r);
|
|
@@ -162,24 +162,15 @@ public class SoundServiceImpl implements SoundService {
|
|
|
maxLength = pitchs_r.size();
|
|
|
}
|
|
|
|
|
|
- if(maxLength>0){
|
|
|
- l_s = new BigDecimal(pitchs_s.get(pitchs_s.size() - 1));
|
|
|
- pitchs_s.remove(pitchs_s.size() - 1);
|
|
|
- l_r = new BigDecimal(pitchs_r.get(pitchs_r.size() - 1));
|
|
|
- pitchs_r.remove(pitchs_r.size() - 1);
|
|
|
- maxLength = maxLength-1;
|
|
|
- }
|
|
|
-
|
|
|
double pitchSize = 0;
|
|
|
double allPitchGap = 0;
|
|
|
for(int i=0;i<maxLength;i++){
|
|
|
double pitch1 = Math.abs(pitchs_s.get(i));
|
|
|
double pitch2 = Math.abs(pitchs_r.get(i));
|
|
|
double pitchGap = Math.abs(pitch1-pitch2);
|
|
|
- if(pitchGap>pitch1){
|
|
|
+ if(pitchGap>pitch1||pitchGap>20){
|
|
|
pitchGap = pitch1;
|
|
|
- }
|
|
|
- if(pitchGap<13){
|
|
|
+ }else if(pitchGap<5){
|
|
|
pitchGap = 0;
|
|
|
}
|
|
|
allPitchGap+=pitchGap;
|