我需要对声音进行分析,以检查声音是否受到阻碍或删除。
import java.net.URL;
import javax.swing.*;
import javax.sound.sampled.*;
public class LoopSounds {
public static void main(String[] args) throws Exception {
URL url = new URL(
"http://pscode.org/media/leftright.wav");
Clip clip = AudioSystem.getClip();
AudioInputStream ais = AudioSystem.
getAudioInputStream( url );
clip.open(ais);
URL url2 = new URL(
"http://pscode.org/media/100_2817-linear.wav");
Clip clip2 = AudioSystem.getClip();
AudioInputStream ais2 = AudioSystem.
getAudioInputStream( url2 );
clip2.open(ais2);
// loop continuously
clip.loop(Clip.LOOP_CONTINUOUSLY);
clip2.loop(Clip.LOOP_CONTINUOUSLY);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// A GUI element to prevent the Clip's daemon Thread
// from terminating at the end of the main()
JOptionPane.showMessageDialog(null, "Close to exit!");
}
});
}
}
但是我将在两种声音之间进行比较,并且需要提取数值进行分析。
最佳答案
AudioInputStream具有read()方法。
您可以创建如下函数:
public void compareVoices(AudioInputStream ais,AudioInputStream ais2){
for(int i = 0;i>ais.getFrameLength;i++){
if(ais.read()!=ais2.read()){
return(false);
}
}
return(true);
}
注意:仅当这两个.wav文件的与完全相同时,此功能才起作用。
关于java - 如何从Java中的音频文件中提取数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42379234/