|
@@ -6,6 +6,7 @@ import be.tarsos.dsp.AudioProcessor;
|
|
|
import be.tarsos.dsp.SilenceDetector;
|
|
|
import be.tarsos.dsp.beatroot.BeatRootOnsetEventHandler;
|
|
|
import be.tarsos.dsp.io.PipedAudioStream;
|
|
|
+import be.tarsos.dsp.io.TarsosDSPAudioFormat;
|
|
|
import be.tarsos.dsp.io.TarsosDSPAudioInputStream;
|
|
|
import be.tarsos.dsp.io.jvm.AudioDispatcherFactory;
|
|
|
import be.tarsos.dsp.onsets.ComplexOnsetDetector;
|
|
@@ -15,6 +16,7 @@ import com.ym.mec.biz.dal.dao.SysMusicScoreDao;
|
|
|
import com.ym.mec.biz.dal.entity.SysMusicScore;
|
|
|
import com.ym.mec.biz.service.SoundService;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -24,9 +26,13 @@ import javax.sound.sampled.AudioFileFormat;
|
|
|
import javax.sound.sampled.AudioFormat;
|
|
|
import javax.sound.sampled.AudioSystem;
|
|
|
import javax.sound.sampled.UnsupportedAudioFileException;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
@@ -119,11 +125,21 @@ public class SoundServiceImpl implements SoundService {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- AudioFileFormat sourceFile = AudioSystem.getAudioFileFormat(new URL(sysMusicScore.getUrl()));
|
|
|
- double l_s = sourceFile.getFrameLength()/sourceFile.getFormat().getFrameRate();
|
|
|
+ URL url = new URL(sysMusicScore.getUrl());
|
|
|
+ String filePath = FileUtils.getTempDirectoryPath()+ Math.random() + ".mp3";
|
|
|
+ File f = new File(filePath);
|
|
|
+ FileUtils.copyURLToFile(url, f);
|
|
|
+
|
|
|
+
|
|
|
+ PipedAudioStream file_s = new PipedAudioStream(filePath);
|
|
|
+ TarsosDSPAudioInputStream stream_s = file_s.getMonoStream((int) sampleRate,0);
|
|
|
+
|
|
|
+ System.out.println(stream_s.getFrameLength());
|
|
|
+ double l_s = stream_s.getFrameLength()/stream_s.getFormat().getFrameRate();
|
|
|
System.out.printf("源长度:%.2f \n", l_s);
|
|
|
+
|
|
|
AudioFileFormat recordFile = AudioSystem.getAudioFileFormat(record.getInputStream());
|
|
|
- double r_s = sourceFile.getFrameLength()/sourceFile.getFormat().getFrameRate();
|
|
|
+ double r_s = recordFile.getFrameLength()/recordFile.getFormat().getFrameRate();
|
|
|
System.out.printf("录音长度:%.2f \n", r_s);
|
|
|
|
|
|
//相似度
|