|
@@ -84,25 +84,29 @@ public class SoundServiceImpl implements SoundService {
|
|
|
* @param bytes: 文件字节
|
|
|
* @return java.util.List<java.lang.Double>
|
|
|
*/
|
|
|
- private List<Double> soundPressureLevelExtractor(byte[] bytes, String url) throws UnsupportedAudioFileException, IOException {
|
|
|
+ private List<Double> soundPressureLevelExtractor(byte[] bytes, String url, Double duration) throws UnsupportedAudioFileException, IOException {
|
|
|
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);
|
|
|
dispatcher.addAudioProcessor(new AudioProcessor() {
|
|
|
@Override
|
|
|
public void processingFinished() {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean process(AudioEvent audioEvent) {
|
|
|
+ t[0] = audioEvent.getEndTimeStamp();
|
|
|
pitchs.add(Double.isInfinite(silenceDetecor.currentSPL())?0:silenceDetecor.currentSPL());
|
|
|
return true;
|
|
|
}
|
|
|
});
|
|
|
dispatcher.run();
|
|
|
+ duration = t[0];
|
|
|
return pitchs;
|
|
|
}
|
|
|
|
|
@@ -139,8 +143,8 @@ public class SoundServiceImpl implements SoundService {
|
|
|
double l_r = 0;
|
|
|
|
|
|
//相似度
|
|
|
- List<Double> pitchs_s = soundPressureLevelExtractor(null, filePath);
|
|
|
- List<Double> pitchs_r = soundPressureLevelExtractor(record.getBytes(), null);
|
|
|
+ List<Double> pitchs_s = soundPressureLevelExtractor(null, filePath, l_s);
|
|
|
+ List<Double> pitchs_r = soundPressureLevelExtractor(record.getBytes(), null, l_r);
|
|
|
|
|
|
int maxLength = pitchs_s.size();
|
|
|
if(pitchs_r.size()<maxLength){
|